Apache deflate/gzip module
-
Hi,
How can I enable gzip compression on a local laravel project, I've tried many tutorials but none seem to work.
I would appreciate any directions/suggestions.
Greetings
-
@RezRazi: gzip compression is enabled by default in Laragon. Check Apache's configuration file (Menu > Apache > httpd.conf)
LoadModule deflate_module modules/mod_deflate.so
-
I did that, but still gzip is not enabled when checking with curl/chrome dev tools
Any direction to get it to work for a laravel project with laragon ?
-
Have you added these to your .htaccess: https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess#L713-L795 ?
Just tested with my setup. Using
LoadModule deflate_module modules/mod_deflate.so
and aforementioned.htaccess
configs, gzip/deflate works fine (amount transferred 1MB -> 490KB), so it's probably either one.
-
For anyone trying to enable gzip/deflate on Laragon. In my case of fresh Laragon installation gzip was NOT enabled. To enable it I followed this answer on Stackoverflow: https://stackoverflow.com/a/6993377
Basically you have to:
- Open Laragon
- Menu > Apache > httpd.conf
- Find and uncomment (remove the leading # character):
- #LoadModule headers_module modules/mod_deflate.so
- #LoadModule filter_module modules/mod_filter.so
- On the end of the file httpd.conf file add:
<Directory "C:/laragon/www">
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
</IfModule>
</Directory> - Restart Laragon (although just reloading Apache should be enough)
This will only enable gzip on html files, if you want to compress other files you will have to add them to the list.
-
@maciej-laskowski could you please remove the words "list item" from the line "#LoadModule filter_module modules/mod_filter.so"?
Also instead of modifiyng the httpd.conf file, one could use a .htaccess file in the root of your virtual host which has this content:
# Deflate Compression by FileType <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-shockwave-flash AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/woff #Don't compress content which is already compressed SetEnvIfNoCase Request_URI \ \.(gif|jpe?g|png|swf|woff|woff2) no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </IfModule>
-
@jmartsch sure, good catch