我在我的_init.php
中使用了一些php代碼來將版本號添加到css文件名中。
現在大多數瀏覽器都會將不同查詢字符串的網址看作不同文件並下載新副本。大多數CDN甚至支持並推薦這一點。更多在這裏:css-tricks.com
這裏是PHP:
// Set path and url
$assets_path = $config->paths->templates . "your-folder/";
$assets_url = $config->urls->templates . "your-folder/";
$file_css = "app.css";
// Generate css version addon
// Check if file exists and get date of last change
if (file_exists($assets_path . $file_css)) {
$css_version_addon = "?v" . date("His", filemtime($assets_path .
$file_css)); // Time of last change 23h 59m 59s in format 235959
} else {
$css_version_addon = "?somethingWentWrong";
}
// Full url with css file and version addon
$css_with_version = $assets_url . $file_css . $css_version_addon;
可以輸出它在你的模板
// In your template file
<link rel="stylesheet" href="<?php echo $css_with_version; ?>" />
// This will output to something like this
<link rel="stylesheet" href="/site/templates/your-folder/app.css?v101525" />
我在我所有的ProcessWire模板中使用此。正如@ jmartsch所說,有很多策略,但這個最適合我。 你如何生成你的文件並不重要(我正在使用scss和gulp來生成css)。腳本只是檢查文件是否被修改並輸出更改時間。
歡迎來到processwire world ..好選擇;)一些問題:也許瀏覽器緩存?你使用什麼安裝配置文件?你有沒有改變你的.htaccess中的任何東西?你如何引用CSS(你有什麼改變)? sass編譯器的工作總是正確的? – Can