Disable on AMP pages
-
Actually, in AMP pages generated by AMP Plugin, W3TC still prints the minfied and concatenate CSS and JS but it shouldn’t. It makes AMP validation to fail.
W3TC still should cache HTMLn, and do HTML and inline CSS minification, but not to include all the CSS from theme and plugins.
-
I always use manual minification mode and that doesn’t fix the issue. I’m sorry but I have to say once again that it seems you are talking about a different issue.
Read de AMP docs, loading a CSS file is not allowed. All CSS styles should be in
<style amp-custom>
tag but W3TC adds the minified CSS file to AMP pages in a<link>
tag, which is not allowed in AMP specification. That is the problem we are talking about in this thread.Same applies for JS. W3TC add the mifified JS file to AMP pages but it shouldn’t.
So, we are discussing about how to disable this behaviour of W3TC and avoid those minified CSS and JS files being added to AMP pages. Changing the minification method can not help with this. It seems you talk about another issue.
Hi,
my solution is adding an action to pre_amp_render_post and setting
$wp_query->is_feed = 1No css and js and html minified. To have the AMP page cached, feed caching in
Page Cache settings must be checked// Avoid minified css and js beeing added to AMP pages add_action( 'pre_amp_render_post', 'amp_avoid_w3tc_minified_css_js' ); function amp_avoid_w3tc_minified_css_js() { global $wp_query; $wp_query->is_feed = 1; }
Interesting Marco. But not sure if this can produce issues in the future, but interesting.
Hi guys, I had a similar problem, W3 Total Cache was adding a <script> tag with the path for a minified JS and this was invalidating my APM blog posts.
I solved (still waiting Google to display the AMP pages in the search results, anyway from console there are no error but one message that says:”Powered by AMP ? HTML”)
My solution was to go in W3 Total Cache > Minify > Advanced > Never minify the following pages and type /amp/ in the text area.
NOTICE: My permalinks are set as “Post Name” so they look like a folder sequence https://mywebsite.com/sample-post/
The AMP plugin by default just add the text /amp/ to the post link, so now every link ending by /amp/ are not minified by W3 Total Cache.
Not a big deal as an AMP page is supposed to be quite small anyway.Hope this will help.
Hello @pandorino. That solution is already commented in a previous comment. The problem is that it skips HTML cache as well. Note that caching HTML for AMP pages is a desired feature (I mean, caching the document), including JS and CSS are not.
Hi @cybmeta!
I just wanted to thank you from the bottom of my heart. Your piece of code (quick fix) works great on my side. You have saved me a lot of time and headaches.
Cheers!
This occurs in manual minification and is obviously a bug.
Won’t happen in automatic because in automatic W3TC sees all the scripts enqueued and minifies and concatenates them. Since it won’t see the scripts in automatic for AMP pages, it won’t add the minified js file(s).
There is another solution for manual.
I haven’t tried but in templates, manually keep adding JS files for different templates instead of choosing “All Templates”.
Involves some work and I am not sure as well. Anyone wishes to try?
anyone interested to collaborate at community edition of w3tc on github
At the beginning of october 2016, along with version 0.9.5.1, a built in W3 Total Cache extensión was released to support Accelerated Mobile Pages (AMP) so now we just have to go and activate it.
Hi @diegocanal!! I know about that update, and about the fork that fixed this and lot more issues earlier, including security issues. Anyway, I don’t use W3TC anymore, the poor communication that its developers had for so long time, even for people who bought premium support, made me switched to other cache solution some time ago, and I’m happy with the change.
@diegocanal I’ve enabled that extension, but I’m still getting problems.
For example, if I edit a post title, the corresponding amp page cache isn’t purged. The same happens if I try the other fixes suggested here from @cybmeta and others.
Does anybody knows how to fix this behaviour? I really need to have my amp pages purged each time I edit the corresponding post.
- This reply was modified 8 years, 1 month ago by folettiwebdesigner.
Hi @cybmeta, yeah, it’s been really frustrating the lack of support and maintenance, I, too, was already considering switching to other cache solution although I didn’t take the step.
I have used W3TC for 4 years. Once I learnt how to make the most of it I started getting very good results, even for quite complex sites —Google PageSpeed Insights 100/100 on both, mobile and desktop (with the addition of 2 more plugins)—.
Unfortunately, lately, I’ve been having great concerns regarding, mainly, the security issues you’ve mentioned. The good news is that those issues have apparently been solved with the recent updates. I hope that, from now on, the plugin will remain well maintained in a timely and effective way.
I must point out that I’ve never had the need of premium support so I haven’t had to endure what allegedly many people have gone through.
Having said that, it is my obligation to say that Frederick Townes, for a long time, has provided me with a terrific plugin —I am not a programmer so I cannot tell how well coded it is, I speak purely from the end-user perspective— a free solution that has allowed me to offer a much better experience to my sites’ users and, of course, improve my business bottom line. For all that I want to show my respect for his work and say…thank you, Frederick!
- This reply was modified 8 years, 1 month ago by diegocanal.
Things go and come. And that is always good, @diegocanal
Hey @folettiwebdesigner, same behavior on my side.
The only way I’ve found to get my amp pages (posts) purged after editing and saving the original posts is to ‘Purge all caches’ —notice that ‘Purge modules’ >> ‘Page Cache: Current Page’ does not do the trick—.
- This reply was modified 8 years, 1 month ago by diegocanal.
- This reply was modified 8 years, 1 month ago by diegocanal.
Exactly, but obviously to purge everything after each post change would mean to make the cache plugin itself pretty useless…
I really hope that someone could at least point out a workaround, because otherwise I can’t enable AMP pages on my website at all.
- The topic ‘Disable on AMP pages’ is closed to new replies.