HTML5 Boilerplate .htaccess cache busting not working with WordPress
Asked Answered
E

3

9

The .htaccess cache settings for HTML5 Boilerplate (http://html5boilerplate.com/) are awesome, but I'm running into an issue with the cache busting settings for JS and CSS versioning.

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>

I can't seem to get this to work with the WordPress rewrite settings already present in the .htaccess file.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>

At best, the rewrite on my JS files never happens. At worst, it breaks the site.

Anyone had any luck getting this to work with WordPress?

Electroform answered 3/4, 2013 at 2:17 Comment(3)
So it's been six months. Not a single response? Amazed!Electroform
"At best, the rewrite on my JS files never happens. At worst, it breaks the site." Does that mean script.000.js -> 404 not found; something -> 500 server error?Planchette
3 things to play around with: 1-Turn off any WP cacheing (JetPack). 2-Append rand var to end of JS/CSS via get param will spoof "new file" and cache is killed. 3-Recently (past 9-12 months) I have noticed that browsers are caching HARDER, esp when using modern JS w/ hash/# use. (The hash stifles fresh reload). What is the cache scenario? Local dev/prod/server type (nginx is different for example).Gym
P
0
  • Make sure your cache-busting URLs actually match the rewrite pattern (script.0.js)
  • Put cache-busting rewrite rules before WordPress's
  • If you can access the server config and read the logs, set RewriteLog 2 (or higher) and then look at the rewrite logs. They're hard to follow but they can give you some clues.
  • "At worst, it breaks the site." If that means you're getting 500 server error, check your server logs -- it will tell you if there's a rewrite loop.

Change WordPress's rule to

RewriteRule ^[\w/-]+$ /index.php [L]

and see if that helps.

At best, the rewrite on my JS files never happens.

Are you seeing WordPress's "not found" response or Apache's?

At worst, it breaks the site.

Apache server error or WordPress error?

Planchette answered 10/10, 2013 at 17:23 Comment(0)
A
0

Can you make some php.ini settings embeded into your .htaccess and then test website for changes, Just to test even if you .htaccess file working or not?

In most cases I have experienced that, there are a few hidden files which CentOS 5.5 based systems does not show (don't know if its already known bug). But if you create a new file with same name .htaccess you will see a few different lines than your original one.

Simply means both are two different files. So just try to check which one is working with your website. Moreover for compressing JS and CSS files, I have written a quite detailed tutorial here http://www.codeandcommand.com/web-based/how-to-optimize-joomla-3-x-pagespeed.html

Afrikander answered 28/4, 2014 at 14:53 Comment(0)
D
0

Try these

<IfModule mod_expires.c>
  ExpiresActive off
</IfModule>
<IfModule mod_headers.c>
  Header unset Cache-Control
</IfModule>
Dunford answered 17/2, 2015 at 22:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.