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
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?
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
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!
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.
re. GitHub; think the easiest way is to
- go to https://github.com/futtta/autoptimize/blob/master/classes/autoptimizeCache.php
- click on edit upon which GH will automatically create a fork
- add those 4 lines
- save
- check if all is OK
- 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.
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 š
Thanks for the help, I followed the steps you listed and made the pull request.
Is this stable to use now?
I see it’s not in the options yet.
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.
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
maybe something like this?