Apache deflate/gzip module


  • | 79 points

    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


  • administrators
    | 128036 points

    @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
    

  • | 79 points

    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 ?


  • | 4363 points

    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.soand aforementioned .htaccess configs, gzip/deflate works fine (amount transferred 1MB -> 490KB), so it's probably either one.


  • | 210 points

    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:

    1. Open Laragon
    2. Menu > Apache > httpd.conf
    3. Find and uncomment (remove the leading # character):
    • #LoadModule headers_module modules/mod_deflate.so
    • #LoadModule filter_module modules/mod_filter.so
    1. On the end of the file httpd.conf file add:
      <Directory "C:/laragon/www">
      <IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html
      </IfModule>
      </Directory>
    2. 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.


  • | 1221 points

    @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>
    

  • | 210 points

    @jmartsch sure, good catch :)


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.