简体   繁体   English

将Rails的CSS样式表用于其他CMS或网站

[英]Use Rails' CSS stylesheet for other CMS or sites

When a CSS is called from a browser, Rails combined all CSS files into one: 从浏览器调用CSS时,Rails将所有CSS文件合并为一个:

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. 我正在与Wordpress共享此CSS文件,并且我希望Wordpress调用相同的CSS,以减少HTTP请求。 But if I put all.css, it will call a fresh CSS from Rails, result in redownloading the CSS file. 但是,如果我输入all.css,它将从Rails调用新的CSS,导致重新下载CSS文件。

What do I do to have Wordpress to just used the cached CSS file with the same section-id? 如何让Wordpress仅使用具有相同section-id的缓存CSS文件?

The "random number" after assets in Rails is the file mtime. Rails中资产后的“随机数”是文件mtime。 To do something similar in Wordpress: 在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. 如果您强制刷新,或者您没有在CSS文件上正确设置有效期标头,则浏览器将下载CSS的新副本,但是如果没有cachebuster字符串,则当文件被释放时,它不会下载新副本变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM