• Resolved Draikin

    (@draikin)


    Both WP Super Cache and CacheEnabler have the ability to create .gzip compressed files alongside the regularly cached .htm pages. Nginx can take advantage of that (although I ran into some problems with it trying to gzip files twice) with the gzip_static option, making it look for those pre-gzipped files and serve those directly, rather than compressing them on the fly with each request.

    I haven’t looked into this yet myself (might be willing to give it a try), but I’m curious if this would be difficult to implement such an option in Autoptimize?

    https://www.ads-software.com/plugins/autoptimize/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Frank Goossens

    (@futtta)

    should be do-able really, have a look at autoptimizeCache.php lines 45-61, where in the else-block you would need to do something similar as on line 55 (behind a filter, pretty please). Do fork on github & issue a pull request when finished (but I won’t merge until after 2.1 has been released) ??

    frank

    Thread Starter Draikin

    (@draikin)

    Thanks for the help! I haven’t done a lot of WordPress development, so bear with me ?? This seems to be working:

    } else {
    			// Write code to cache without doing anything else
    			file_put_contents($this->cachedir.$this->filename,$code, LOCK_EX);
    			if (apply_filters('autoptimize_cache_create_gzip',true)) {
    				// Create an additional cached gzip file
    				file_put_contents($this->cachedir.$this->filename.'.gzip',gzencode($code,9,FORCE_GZIP), LOCK_EX);
    			}
    		}

    Is this what you had in mind when you said “behind a filter”? Contrary to what I posted above, I’m guessing you’d want this to be disabled by default? Or would this be worth adding an option in the Autoptimize menu for?

    Plugin Author Frank Goossens

    (@futtta)

    think you nailed it, but indeed would prefer the filter to have false as default (for now) and for it to be named autoptimize_filter_cache_create_static_gzip?

    people who care about gzipping won’t mind having to do

    add_filter('autoptimize_filter_cache_create_static_gzip','__return_true');

    ??

    frank

    Plugin Author Frank Goossens

    (@futtta)

    and as it’s a small change which would be off by default, i could still include it in 2.1 anyhow. looking forward to your pull-request on github! ??

    do make the change based on the state of the master branch there, to avoid any merging conflict. that way you can also try out 2.1 already, I desperately need some testers/ feedback!

    Thread Starter Draikin

    (@draikin)

    I’ll do that, thanks. I’ll look into making a pull request, but I must admit I haven’t worked with Github a lot and I messed up with the pull requests when I contributed to Jetpack some time ago.

    You’re correct in that people won’t mind applying the filter to enable the creation of gzip files. To be honest I’m not sure how much of a speed boost and decrease in CPU usage this actually grants, but I don’t see a downside to enabling it if you’re already using Nginx gzip_static anyway.

    On a side note, did you never run into problems serving Gzip content from PHP in combination with Nginx? I had some weird issues with both WP Super Cache en CacheEnabler in that scenario. Nginx would appear to gzip the content again, causing decoding errors in the browser, even if gzip was disabled altogether in Nginx.

    Plugin Author Frank Goossens

    (@futtta)

    re. GitHub; think the easiest way is to

    1. go to https://github.com/futtta/autoptimize/blob/master/classes/autoptimizeCache.php
    2. click on edit upon which GH will automatically create a fork
    3. add those 4 lines
    4. save
    5. check if all is OK
    6. create the pull request

    re. speed boost/ CPU decrease; I suppose it will not be huge, but every ms counts, so ??

    re. gzip+php+nginx; no experience what-so-ever with nginx i’m afraid.

    Plugin Author Frank Goossens

    (@futtta)

    do you think you’ll be able to do the github-dance one of these days draikin? I could add your change in myself, but I’d prefer you to get the contributor-attribution on GitHub ??

    Thread Starter Draikin

    (@draikin)

    Thanks for the help, I followed the steps you listed and made the pull request.

    Plugin Author Frank Goossens

    (@futtta)

    super!

    Is this stable to use now?
    I see it’s not in the options yet.

    Plugin Author Frank Goossens

    (@futtta)

    this is (and probably will remain) an API-only option @funsail ??

    edit; but it is in 2.1, you’d have to do this to enable creation of gzip-files;

    add_filter('autoptimize_filter_cache_create_static_gzip','__return_true');

    OK
    No reason not to use this right? Supercache zips our html.

    Plugin Author Frank Goossens

    (@futtta)

    well, 2.1 saves the files as .gzip whereas as per the way things are done it should be .gz. this is fixed on the dev-version, so you might want to download that (overwrite wp-content/plugins/autoptimize with the contents of autoptimize-master in the zip-file).

    also take into account that you’ll have to change your webserver config (in .htaccess if on Apache) to use the .gz files if available).

    have fun!
    frank

    Hmm, yes I was just going to ask how to change htaccess
    the supercache code is complex, I don’t know how i’d write my own

    Plugin Author Frank Goossens

    (@futtta)

    maybe something like this?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Creating pre-gzipped cached files?’ is closed to new replies.