Gzip output not used. #76

Closed
vijayaraghavanramanan opened this Issue Jan 6, 2017 · 4 comments

Projects

None yet

2 participants

@vijayaraghavanramanan

Hi Frank,

Your plugin now supports creation of pre-gzipped files. I have enabled them using:

add_filter('autoptimize_filter_cache_create_static_gzip','__return_true');

However this file doesn't seem to be used and the server is gzipping everytime. My conclusion is based on the observation that the content-length as seen from Chrome development tools is higher than the static gzip file.

I think you need to add headers in htaccess asking the server to use the gzip file instead of dynamically compressing.

Code here

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


    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped & 
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
</IfModule>
@futtta
Owner
futtta commented Jan 6, 2017

that's correct, when enabling gz creation with the filter you still have to change your .htaccess (or nginx equivalent). people who can use filters can also change a .htaccess ;-)

@vijayaraghavanramanan

True, but won't updates potentially overwrite this?

@futtta
Owner
futtta commented Jan 9, 2017

changes to your root .htaccess are not overwritten no :)

@futtta
Owner
futtta commented Jan 9, 2017

closing as intended behavior ;-)

@futtta futtta closed this Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment