views:

40

answers:

1

When a CSS is called from a browser, Rails combined all CSS files into one:

all.css?random-section-id-number (e.g. all.css?2342568659756352)

Each time it expires, the number changes.

I am sharing this CSS file with Wordpress, and I want Wordpress to call the same CSS so that it reduces the HTTP request. But if I put all.css, it will call a fresh CSS from Rails, result in redownloading the CSS file.

What do I do to have Wordpress to just used the cached CSS file with the same section-id?

A: 

The "random number" after assets in Rails is the file mtime. To do something similar in Wordpress:

<? $stat = stat("/path/to/your/railsapp/stylesheets/stylesheet.css"); ?>
<link rel="stylesheet" type="text/css" href="/railsapp/stylesheets/stylesheet.css?<?=$stat["mtime"] ?>" />

That said, the purpose of that string isn't to help caching, but to act as a cache-buster when the file changes. Your browser will download a new copy of the CSS if you force-refresh, or you aren't setting an expiry header on the CSS file properly, but without the cachebuster string, it wouldn't know to download a new copy when the file changes.

Chris Heald
So I should put the code above in the header of the Wordpress template file? $stat = stat("/path/to/your/railsapp/stylesheets/stylesheet.css"); Also, can I use absolute path? Thanks.
Victor