Something strange is happening here with Autoptimize… The JS options are completly without any effect when I do not enable HTML options, too. And more weird, if I enable Keep HTML comments JS options are ignored again.
So either Autoptimize does not optimize JS or it breaks NextGen Gallery here (as I need Keep HTML comments for that).
Any hints? I’m happy to provide any information you need. I am using the newest version of the plugin. I am using a caching plugin, too, but the effects are the same with disabled caching.
That indeed is strange, esp. as the JS optimization is done before the HTML optimization and that while doing JS optimization the HTML-comments ar hidden from view by encrypting them temporarily. Does this also impact CSS optimization?
Still, the answer must be somewhere in the HTML comments. Anything special in there? How does NG gallery use those?
CSS optimization seems to work. At least I do not see all the CSS files I see when Autoptimize is disabled. The website is http://t.co/flE7N6vxme , take a look if you like. I do not see anything out of the ordanary. What Autoptimize options you see: HTML on, HTML comments off, JS on with some excludes, CSS on with some excludes.
I’m sure some of those are not necessary, but at least I managed to get my website working with those excludes.
I’m testing with NextGen Gallery myself now and can confirm some … weirdness. I’ll keep you posted.
Weirdness. That’s the word. 😉 Thank you for digging into this and I am glad that it is not just me. Which means that it is more likely that it can be fixed.
Have been digging into NextGen Gallery, that is one funky plugin!
Apparently NGG inserts an HTML-comment early (before AO runs), which is then used late (after AO has done it’s job) to insert JS. So if AO removes the early comment, the late JS-insertion gets broken.
I’m now adding some code in autoptimizeHTML.php to allow it to exclude strings from optimization. Doing so will fix the breakeage with NextGen Gallery, but as the NGG JS is inserted after AO runs, the NGG-JS won’t be optimized by AO.
I’ll be back with a test-version soon.
It seems that messing up with the NGG code does not make any sense anyway as the galleries simply do not work. It gets even harder if you try to get the Pro version up and running with caching and/or minify and/or optimizations. So an optimized website without NGG optimization would be a lot better than no optimizations at all.
Is this also reason why Autoptimize does not do anything with JS if I do not turn on HTML and HTML comments?
PS: If you checked my site then you might have seen that no JS is stripped from the source code, also JS from other plugins which are not on the exclude list. That’s what I was thinking about the complete last evening and then checking and checking the exclude list versus the source code.
Well, I limited my investigations to NextGen Gallery + Autoptimize, there might be other issues on your site as well that we can look into once we get NGG working OK. That being said; I did check NGG on my testblog with JS & CSS and no HTML-optimizatoin and that works OK (when “forcing JS in head”, as NGG depends on a.o. jquery being loaded early).
So the test-version is ready; the changes are all in /wp-content/plugins/autoptimize/autoptimizeHTML.php and you can download an updated Autoptimize zip-file here. Would be great if you could give that a spin and report back.
I just applied the changes to /trunk on wordpress.org plugin repo as well, so now you can download the to-be-1.9.3 there as well.
Thank you – I just downloaded the test version.
Unfortunally nothing changed. Or to be more specific: It is even worse. No more JS optimization is taking place. No matter what I turn on or off in the HTML section.
You can see this when checking the source. Stuff like this (and more) is still in the code:
I did not set any excludes for these scripts.
A question about NGG or in general about my JS exclude list: If I put the JS stuff in the head like you suggest I might can clean the list a bit? Like jquery? In general: Did you see any other excludes which might not be needed when putting the JS stuff into the head?
Well, can’t speak for all plugins, but I did get NGG working with just “force JS in head” and not excluding anything.
Regarding files not being aggregated; are you running a setup with a (caching) reverse proxy of some kind and WordPress being on another domain then the one used to visit (as configured for “WordPress Address (URL)” and “Site Address” in “General Settings”?
No I do not have anything like this. The only a bit not common is the https setup instead of http.
Autoptimize worked when I first installed it some months ago. Then between then and now there is no JS optimization anymore. I did not check at every upgrade if everything is still working ok.
- The topic ‘JS options don't work if HTML disabled’ is closed to new replies.