dana-ross / http2-server-push

WordPress plugin that enables HTTP/2 server push for local JavaScript and CSS resources enqueued in the page.
MIT License
30 stars 5 forks source link

Honor W3 Total Cache CDN settings #16

Open marcelstoer opened 7 years ago

marcelstoer commented 7 years ago

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.

dana-ross commented 7 years ago

Some notes on this issue:

marcelstoer commented 7 years ago

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.

awhig commented 6 years ago

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.