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

Open
wants to merge 1 commit into
base: develop
from

Conversation

Projects
None yet
4 participants
@Eihrister
Contributor

Eihrister commented Aug 24, 2017

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.

Daniël Mostertman
Precompression for (pipelined) assets (nginx::gzip_static support).
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.
@OleVik

This comment has been minimized.

Contributor

OleVik commented Aug 28, 2017

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?

@Eihrister

This comment has been minimized.

Contributor

Eihrister commented Aug 28, 2017

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
Apache: https://stackoverflow.com/questions/16883241/how-to-host-static-content-pre-compressed-in-apache

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

This comment has been minimized.

@rhukster

rhukster Sep 5, 2017

Member

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;
}

This comment has been minimized.

@rhukster

rhukster Sep 5, 2017

Member

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.

@jimblue

This comment has been minimized.

jimblue commented Feb 10, 2018

Any update about this PR @Eihrister ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment