-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Precompression for (pipelined) assets (nginx::gzip_static support). #1621
base: develop
Are you sure you want to change the base?
Conversation
Compressing resources on-the-fly adds CPU-load and latency (wait for the compression to be done) every time a resource is served. nginx offers another way of doing things, and it's called gzip_static. http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html If you enable gzip_static, nginx will look for $filename.gz and serve that directly, so no extra CPU-cost or latency is added to your requests, speeding up the serving of your website. This feature adds support to directly compress asset files when they are written to disk by the Grav\Common\Assets class. Using this feature you can also specify the compression level (default to the maximum of 9). Since you only have to compress every resource only once, using the maximum compression level is an ideal default.
This seems to be specific for Nginx? Whilst handy, it would be superfluous for all other webservers. Also, have you tested it with other webservers to ensure that the settings causes no issue with them? |
Hi Ole, For other webservers it will not cause problems, as it is merely creating an additional file. nginx supports it by default without requiring any extra work. However, support is not limited to nginx. Other webservers can also make use of it, if configured accordingly. Some searching can find some ways to set it up: Lighttpd: http://redmine.lighttpd.net/issues/611 I'm sure it could work in any webserver software as long as you configure it properly. If I could've done it in a plug-in, I would've. I have purposefully avoided using "nginx" in the code / descriptions of things, as it is what it is: precompression of files. I understand that it might seem unusual to put this in the core, but to me it didn't really seem to have another place. It's either upon creation of said resources, or doing everything by hand externally out of Grav, not knowing when asset files are created. Daniël |
type: number | ||
min: 1 | ||
max: 9 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you have provided updates to system.yaml with translations for this field, however, those translations need to be added to the admin/languages/en.yaml
file as the 'source' language file.
} | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it not possible to perform this functionality with the RocketTheme\Toolbox\File\File
class? We use this class throughout Grav to read/save files. That way it would be more consistent an not need all the manual low-level PHP file calls.
Any update about this PR @Eihrister ? |
lighttpd mod_deflate can compress and save the compressed result in a cache if If you pre-compress the files yourself (gzip, brotli, zstd, ...), you can use lighttpd mod_magnet to run a small lua script for content negotiation, e.g. content-negotiation.lua |
Compressing resources on-the-fly adds CPU-load and latency (wait for the
compression to be done) every time a resource is served. nginx offers
another way of doing things, and it's called gzip_static.
http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html
If you enable gzip_static, nginx will look for $filename.gz and serve
that directly, so no extra CPU-cost or latency is added to your
requests, speeding up the serving of your website.
This feature adds support to directly compress asset files when they are
written to disk by the Grav\Common\Assets class. Using this feature you
can also specify the compression level (default to the maximum of 9).
Since you only have to compress every resource only once, using the
maximum compression level is an ideal default.