Web2py adn Gzip

65 views
Skip to first unread message

Gaël Princivalle

unread,
Oct 24, 2020, 3:40:11 AM10/24/20
to web2py-users

Hi all.

I have a 4GB cloud plan on Webfaction.

On a specific website page I've made some speed test with and without Gzip enabled.
With Gzip:
PageSpeed Insight Desktop: 78
GTMetrix: 99
GT-Webfaction_2.png

Without Gzip:
PageSpeed Insight Desktop: 66
GTMetrix: 51
GT-Webfaction without Gzip_2.png

Now the Webfaction Web2py customers must migrate to another hosting.
Opalstack seems the best similar solution as this company has been created by Webfaction guys.

I've now also an Opalstack VPN 4BG plan where I've migrated the same Web2py website tested on Webfaction.

The test speed with GTMetrix is quite the same as the Webfaction one without Gzip (a little bit slower) :
GT-Opalstack_2.png

In the Opalstack control panel there's not the possibility to enable Gzip.

Of course I can minify each CSS and Javascript file, and trying like that to improve the speed.

But someone knows if with Web2py it's possible to add Gzip or something similar?
A laziness solution...

Thanks.

Jose C

unread,
Oct 24, 2020, 1:00:18 PM10/24/20
to web2py-users
I requested gzip as well for a static media site (https) and they said:

Our front-end Nginx server will not use gzip compression for requests served over HTTPS. This is by design as a mitigation for the BREACH exploit.

We've an internal feature ticket open to consider making the mitigation optional for customers that don't need it. I will make a note of your inquiry there.


Perhaps you can +1 them on this feature request.

However, if you're serving your static files via web2py itself (and not via a static app on another domain for speed) then web2py will send the .gz file version of a requested asset if it exists.  For example, a request for mysite.css comes in, web2py sends mysite.css.gz automatically if it exists, else it sends mysite.css.

The zip_static_files.py utility in your web2py scripts directory will create gzipped versions of all your static files for you.

HTH,

Gaël Princivalle

unread,
Oct 24, 2020, 2:38:45 PM10/24/20
to web2py-users
>Perhaps you can +1 them on this feature request.
Done.

> The zip_static_files.py utility in your web2py scripts directory will create gzipped versions of all your static files for you.
Great.
However something goes wrong.

[user@vpsXX web2py]$ python web2py.py -S myapp -R scripts/zip_static_files.py
Traceback (most recent call last):
  File "web2py.py", line 41, in <module>
    import gluon.widget
  File "/home/user/apps/web2py_folder/web2py/gluon/widget.py", line 27, in <module>
    from gluon.shell import die, run, test
  File "/home/user/apps/web2py_folder/web2py/gluon/shell.py", line 285
    exec(read_pyc(pycfile), _env)
SyntaxError: unqualified exec is not allowed in function 'run' it contains a nested function with free variables

Do you know why?

Gaël Princivalle

unread,
Oct 24, 2020, 3:09:57 PM10/24/20
to web2py-users
It seems that for a similar error the solution was to update Python to almost 2.7.9.

On Opalstack in the virtualenv I've 2.7.5.
Checking the latest version with python2 --version I obtain 2.7.5.
That's strange as it exists 2.7.16.

Jose C

unread,
Oct 24, 2020, 3:13:23 PM10/24/20
to web2py-users
> The zip_static_files.py utility in your web2py scripts directory will create gzipped versions of all your static files for you.
Great.
However something goes wrong.

hmmm, what is your python version?  And web2py version?  I'm suspecting this tool hasn't been updated to py3.

Jose C

unread,
Oct 24, 2020, 4:14:21 PM10/24/20
to web...@googlegroups.com
On Saturday, 24 October 2020 20:13:23 UTC+1, Jose C wrote:
> The zip_static_files.py utility in your web2py scripts directory will create gzipped versions of all your static files for you.
Great.
However something goes wrong.

 
As a workaround, you could probably quite easily customize the script. 

It looks like it only needs the web2py environment to get the request.folder variable to find the static directory of your app.  If you edit the script and change where it gets which folder to scan and assigns to the static_path variable (by either hardcoding or passing in via command line, for example), you should then be able to run it simply from python (3 or 2) externally without loading the web2py app.

That should overcome the bug.

HTH,


Gaël Princivalle

unread,
Oct 31, 2020, 6:51:26 AM10/31/20
to web2py-users
Hi.

I was working on a http website.
Anyway the https protocol don't accept gzip, so as all websites now are https, it don't have any interest to have gzip.
My https websites load really faster compare to Webfaction.

Good deal.
Reply all
Reply to author
Forward
0 new messages