Reputation: 8054
I am using W3 Total Cache plugin, the plugin is set up to work with AWS-based CDN (S3+CloudFront):
The process above seems to work fine:
style.css
gets minified as 18704.css
and script.js
gets minified as 39633.js
.Automatic upload into the CDN works, I can then manually access the files by typing the URLs into the address bar in the browser:
https://<instance>.amazonaws.com/wordpress/wp-content/cache/minify/1/39633.js
gets found andhttps://<distribution_id>.cloudfront.net/wp-content/cache/minify/1/39633.js
gets foundThe automatic URL rewrite by the plugin (when loading a webpage) is what most likely fails, because the HTML header still has the original hostname in the URL:
<script type="text/javascript" src="https://www.example.com/wp-content/cache/minify/1/39633.js"></script>
<link rel="stylesheet" type="text/css" href="https://www.example.com/wp-content/cache/minify/1/18704.css" media="all" />
Why does the W3 Total Cache plugin not rewrite the URLs with CloudFront as the host?
Chrome's network console: The minified files get pulled from the original host and not the CDN
POSSIBLE WORKAROUND:
This seems like a workaround, but it works. By specifying RewriteRules in .htaccess
file I force the site to load .css
and .js
files via the CDN.
RewriteCond %{REQUEST_URI} \.(css|js)$
RewriteRule ^ https://<distribution_id>.cloudfront.net%{REQUEST_URI} [R,L]
But there is still one files that resists to be redirected (18704.css
). I have my browser cache turned off (even deleted browser cache manually) and the file still resists to be loaded from cache. I think this has nothing to do with browser caching, Chrome's network console says the file is not loaded from cache.
Upvotes: 0
Views: 1496
Reputation: 161
What you need to is to set the minify option to manual and then upload the minify file with w3total cache. enter image description here
Upvotes: 1