Using Autoptimize on Google App engine
-
Hi,
we’re running WordPress on a Google App engine, hence, the filesystem is readonly. We store media on Google Cloud storage, for this we use a plugin.
Do you know if Autoptimize can be run under this circumstances? Do you know or have you heard about a way?
I understand that your base directory is always at least the “wp-content” directory.
Is it possible to use /tmp instead? (Still, I wouldn’t know if it could be served by nginx from there, but this may be another question.)Best regards & thank you!
Wolfram
-
I would imagine
wp-content/uploads
will always have to be read/write somehow, so maybe try setting this constant;define('AUTOPTIMIZE_CACHE_CHILD_DIR','/uploads/autoptimize/');
frank
Hey Frank,
thanks for your answer. I tried that but it didn’t work. We use Google Cloud Storage plugin to read and write media, but it seems not to work in a way that ‘uploads’ becomes a writeable folder.
Another scenario could be to optimize the js and css resources on build and to then to just serve the files. Would that be thinkable? Still, the plugin would permanently notice that the optimize folder is not writable.
Regards!
Wolframif building == having the (dev) site crawled to allow the optimized resources to be generated then it might (mostly) work. combining it with “404 fallback” (requiring and nginx directive to ensure 404’s for
cache/autoptimize
get redirected) would likely make it workable ..Hi Frank,
thank you, yes, building=running in dev, ok, to understand your plugin better: I’d have to run a WP site on dev that includes all js and css – right? To have it all included in one optimized js and one optimized css file, right? Or would I need more files? Is there eg a wp cli command to generate the optimized files?
How does the fall back work?
And can the plugin be told that it doesn’t need write privileges since it doesn’t need to write?
Thanks for all your answers, hope I don’t ask too much!
Wolfram-
This reply was modified 4 years, 5 months ago by
w0lfr4m.
- you will probably have more files; consider a typical homepage vs contact page where the homepage has a slider and the contact page has a form with some JS logic. as a result the homepage will have different JS (and CSS) then the contact page, so the optimized CSS/ JS will be different between them.
- there is no wp cli command, as AO works “on the fly” on a per request-basis.
- upon generating the first CSS/ JS files AO will create a copy of the main JS & CSS-files, naming them
autoptimize_fallback.js
andautoptimize_fallback.css
. if a JS- or CSS-file under cache/autoptimize/ 404’s, the webserver handle those 404’s using/wp-content/autoptimize_404_handler.php
which will take care of the redirect to the fallback files - we might need a small code change for AO not to complain about not being able to write (a filter or constant)
so using AO in this context is possible, but not your “out of the box” approach and this might turn out to be somewhat … “hackish” ??
Hey Frank,
thank you for this detailed answer! Yes it looks hackish, but I don’t know if there are solutions for this purpose under this technology stack. And, in dev, your plugin was working great, just what one would wish, so worth trying.
So there is one JS and one CSS optimized file to be generated for each request/route?
For the fallback files: what do you mean by main JS and CSS file? How would it know what is main?
So in the case of news post, it would redirect to these fallbacks, right?
And yes, for our customer, it’d be great to configure the plugin as “deliver only” mode, or what a better name might be.
Best, Wolfram
-
This reply was modified 4 years, 5 months ago by
w0lfr4m.
So there is one JS and one CSS optimized file to be generated for each request/route?
no, not necessarily; 2 blog-posts or 2 “normal” pages will generally have the same CSS/ JS (esp. if inline CSS/ JS are not aggregated), so there the optimized CSS/ JS would be re-used from cache.
For the fallback files: what do you mean by main JS and CSS file? How would it know what is main?
when clearing the cache, AO will itself automatically generate the CSS/ JS for the homepage (by requesting it itself), it will be the optimized CSS & JS from that first request that will become the fallback file(s).
So in the case of news post, it would redirect to these fallbacks, right?
no, ideally AO would find the optimized CSS/ JS in cache (as per first answer CSS/ JS can be shared between pages)
Hi Frank,
thank you…
If I wanted to exclude files that I rather want to be served from cdns I can do that with “Exclude scripts from Autoptimize:” option in combination with “Minify excluded CSS and JS files?” – correct? Just curious, why does the “Exclude …” option not just exclude, why is the “Minify excluded CSS and JS files?” option necessary?
And what do you think the effort would be to add the configuration in read-only mode?
Best!
Wolframexclude = exclude from being aggregated, but an excluded file might still benefit from being minified, hence the default behavior that can be deactivated with that option.
re. read-only: I’ll tinker with the code a bit and get back to you. might need some back and fro between us for you to test & me to tweak though, hope you’re up for that?
Sounds great, yes, I’ll test! Thanks for your support…I’ll be away from keyboard until Monday or Tuesday, then I can do it…
Regards! Wolfram
OK, first iteration! Use https://gist.github.com/futtta/b105a100072dc4e3e6e9a1b377ae2315 to replace the contents wp-content/plugins/autoptimize/classes/autoptimizeCache.php and then in wp-config.php add
define( 'AUTOPTIMIZE_CACHE_READONLY', true );
and everything test thoroughly?
Hey Frank,
great!!! It works happily! Although I couldn’t test with the engine yet, but what I did:
- overwrite the autoptimizeCache class
- activate the plugin, set it’s settings and empty cache
- open a site to make Autoptimize create optimized files and fallbacks
- set the wp-content/cache folder read-only
I only left the very first and the optimized file in css/ and js/ folder, removed the snippets and it worked fine on my sites, the redirection to the fallbacks as well. And of course, the warning in the backend has gone away.
This is really a great help!!
Are there still issues to test or could that go into a new version? Then it would be easier to deploy. If you want to make sure before: next week I hope I can try to put it manually on our engine.
Is there something I could do for you?
Wolfram
well, AO 2.7.8 will be released early next week and I can add the (limited) changes to autoptimizeCache.php in it. obviously if things go wrong when testing on GAE further changes would require waiting for the next release (for which there is no eta)?
hey, ok so I tested it on GAE but, as you mentioned, it needs the nginx error-page handling and I couldn’t get it to work, yet, I asked for help and hope to get it soon…
I was wondering if offering all the plugin settings in the Backend while being in read-only mode would be confusing to users? But to sort this out would take some time, right? Just asking in general…
Regards!
well, we _could_ add a notifcation “AO is in read-only mode, so changing settings below will have no impact”, that’s pretty easy.
-
This reply was modified 4 years, 5 months ago by
- The topic ‘Using Autoptimize on Google App engine’ is closed to new replies.