Support » Plugin: Fast Velocity Minify » Pre-compressed Gzip – Speed boost!

  • Resolved G

    (@gnetworkau)


    Apache Server Gzip Configuration (htaccess)

    I checked recently the FVM generated files found in [cache directory]/fvm/out/ and discovered 3 files generated for each resource (css or js).

    • 1. The merged file .css/.js (used for browser)
    • 2. The plugin info file .txt (used on FVM Status tab)
    • 3. The 3rd file .gz (gzip) I believe is generated by the cache plugin WP Super Cache – likely its htaccess directives. I have the setting selected “Compress pages so they’re served more quickly to visitors”.
      Generated by FVM.

    What a bonus I thought, pre-compressed gzip FVM css/js files!

    Go and check the directory [cache directory]/fvm/out/ and if it contains the pre-compressed gzip files, you can take advantage of those and get another 10%+ page load speed!

    The following htaccess directives will make sure the resources are served as content-encoding: gzip, whether they are pre-compressed or not, and set appropriate cache control – expires & security – headers too. If the gzip files exist, it will load page/resources just that little bit faster…
    Just add the following to the document root .htaccess file to get the added boost:

    # ===== BEGIN GZIP =====
    # ===== Cache Control and Enable CORS =====
    <FilesMatch "\.(js|css|jpg|gif|png|pdf|swf|svg|svgz|ico|ttf|ttc|otf|eot|woff|woff2|webp)$">
     <IfModule mod_headers.c>
        ExpiresActive On
        ExpiresDefault  "access plus 1 month"
        Header set Cache-Control "public, immutable, max-age=2628000, s-maxage=2628000"
        Header set Access-Control-Allow-Origin "*"
     </IfModule>
    </FilesMatch>
    # Compression by Type
    # text/html removed to allow cached gzip compression by Supercache (add below if required)
    <ifmodule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/css text/javascript text/plain text/xml application/javascript
    </ifmodule>
    <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
        RewriteCond "%{HTTP:Accept-encoding}" "gzip"
        RewriteCond "%{REQUEST_FILENAME}\.gz" -s
        RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]
    # Serve gzip compressed JS files if they exist and the client accepts gzip.
        RewriteCond "%{HTTP:Accept-encoding}" "gzip"
        RewriteCond "%{REQUEST_FILENAME}\.gz" -s
        RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]
    # Serve correct content types, and prevent mod_deflate double gzip.
        RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
        RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
    # Serve correct encoding type, and cache control
        <FilesMatch "(\.js\.gz|\.css\.gz)$">
        Header append Content-Encoding gzip
        ExpiresActive On
        ExpiresDefault  "access plus 1 month"
        Header set Cache-Control "public, immutable, max-age=2628000, s-maxage=2628000"
        Header set Access-Control-Allow-Origin "*"
        </FilesMatch>
    </IfModule>
    # ===== END GZIP =====

    To test on your browser, right-click on a web page, select Inspect or Inspect Element then click the “Network” tab at top. Load/reload page then…
    Scroll thru the files list and click on CSS or JS file to view headers. Should include:
    content-encoding: gzip
    vary: Accept-Encoding
    expires: [future date]

    All good!

    • This topic was modified 9 months, 3 weeks ago by  G. Reason: Correction
    • This topic was modified 9 months, 3 weeks ago by  G.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Raul P.

    (@alignak)

    Hi,

    Yes, that’s one of FVM features and it’s unrelated to supercache.
    https://wordpress.org/plugins/fast-velocity-minify/#faq

    It generates gz files which can be used with the nginx static module or apache.
    It also generates brotli pre compressed files, provided that your system has the php extension installed for it.

    G

    (@gnetworkau)

    Ok, I didn’t see it as a feature for Apache, and as it showed some headers from supercache I suspected it was the source. Great, I like that, as it can be used for added speed as above.
    Sweet!

    G

    (@gnetworkau)

    On the FAQ page it says:

    How do I use the pre-compressed files with gzip_static or brotli_static on Nginx?
    When we merge and minify the css and js files, we also create a .gz file to be used with gzip_static on Nginx. You need to enable this feature on your Nginx configuration file if you want to make use of it. Likewise, if you have Nginx compiled with brotli and have enabled the php-ext-brotli extension for PHP, you can enable the brotli_static option and FVM will also generate .br files for you.

    I think you can add the Apache server to this section, as it works perfectly, and when tested, it improved page load speed by 10% especially the faster TTFB.

    G

    (@gnetworkau)

    I had a look at brotli compression, and decided to enable the Apache brotli module to see what it would do. I could get it to deliver .br files easy enough, but without the nginx brotli_static option there are no brotli version of resources generated by FVM.

    Is there any way to get the FVM .br files generated on Apache?

    I am looking at the FVM plugin code for now…

    Plugin Author Raul P.

    (@alignak)

    For brotli, you need this php extension too.
    https://github.com/kjdev/php-ext-brotli

    Then FVM will generate those for you.

    G

    (@gnetworkau)

    ok, will take a look.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pre-compressed Gzip – Speed boost!’ is closed to new replies.