http2-server-push icon indicating copy to clipboard operation
http2-server-push copied to clipboard

Honor W3 Total Cache CDN settings

Open marcelstoer opened this issue 7 years ago • 3 comments

I use W3 Total Cache (to e.g. set the CDN) and your plugin. However, the two don't play nice.

Chrome warns e.g.

The resource https://frightanic.com/blog/wp-includes/js/wp-emoji-release.min.js?ver=4.7.3 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.

Your plugin preloads https://frightanic.com/blog/wp-includes/js/wp-emoji-release.min.js?ver=4.7.3 but the asset is effectively served from the CDN at https://dziadalnfpolx.cloudfront.net/blog/wp-includes/js/wp-emoji-release.min.js?ver=4.7.3.

That is because the configured CDN hostname is dziadalnfpolx.cloudfront.net whereas your plugin uses host-relative URLs thus preloading from frightanic.com instead. This effectively renders the effect of your plugin moot.

It wouldn't even help if I set a CNAME for the CDN (such as e.g. cdn.frightanic.com) because it'd still be different from the original hostname.

marcelstoer avatar Apr 17 '17 10:04 marcelstoer

Some notes on this issue:

  • w3tc replaces URIs by registering an output buffer, and in the handler it matches regexes and calls functions to replace the URIs with their CDN equivalents.
  • w3tc makes a lot of calls to ob_start().
  • It looks like all of w3tc's init action handlers run at the default priority, except
    • PgCache.php W3_Plugin_PgCache::run, which sets up an init handler at priority 99999 to implement full-page caching
    • Extension_FragmentCache_Plugin::run which sets up an init handler at priority 9999999 to implement a fragment cache

dana-ross avatar Jun 18 '17 21:06 dana-ross

Thanks for the analysis. I don't know enough about the WordPress innards to understand what the consequences of your notes are. It sounds like it won't be possible to "fix" this from your end, though. How about adding a plugin config for a static hostname? If set you'd send absolute URLs rather than relative URLs.

marcelstoer avatar Jun 19 '17 05:06 marcelstoer

I'm noticing this as well, when testing my site using https. CDN settings are ignored for the link preload items placed in the response header.

So my css file and 2 js files are all being loaded twice on my home page. Once from the CDN, and once from my origin server.

Turning off HTTP/2 push on both css and js Minify config removes the Link preload items from the response. But underlying issue should probably be fixed.

awhig avatar Oct 20 '17 21:10 awhig