[WordPress] 外掛分享: Dynamic Asset Versioning

首頁外掛目錄 › Dynamic Asset Versioning
30+
安裝啟用
★★★★★
5/5 分(1 則評價)
3381 天前
最後更新
問題解決
WordPress 4.7+ v0.1.0 上架:2016-12-11

內容簡介

WordPress 資源版本控制有時候會是一把雙刃劍:一方面它能夠極有效地進行緩存破解,確保你不會向瀏覽者分享過時的腳本或樣式。另一方面,手動增加版本號碼是很麻煩的事情(即使是使用常數,也是如此!),往往會導致版本控制記錄充滿“升級版本號碼”提交。

動態資源版本控制的目標就是簡化此流程:如果一個已經入列的資源沒有明確的版本號碼,此外掛會自動獲取文件上次修改的時間戳並使用它作為版本號碼。這很簡單:你觸摸了文件,版本號碼就會自動更新。

使用方式

一旦啟用了動態資源版本控制,它會基於文件修改時間自動獲取版本號碼,對任何已經入列使用wp_enqueue_style() 或 wp_enqueue_script()的[非核心]文件生效。

範例

wp_enqueue_style(
'my-theme-styles',
get_template_directory_uri() . '/assets/css/my-styles.css',
array( 'some-other-styles' ),
false, // 別擔心,動態資源版本控制會為你覆蓋!
'screen'
);

特別感謝

一個特別的感謝要送給10up,他們調劑了這個外掛的原始概念。

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Dynamic Asset Versioning」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

WordPress asset versioning can be a double-edged sword: on one-hand, it’s extremely effective for cache-busting, ensuring you aren’t sharing stale scripts or styles to your visitors. On the other hand, having to manually increment a version number is a pain (even as a constant), often resulting in a version control history full of “bumping the version number” commits.
Dynamic Asset Versioning aims to simplify this process: if an enqueued asset doesn’t have an explicit version number, the plugin will get the timestamp of the last time the file was changed and use that as the version number. It’s easy: you touch the file, the version number is updated automatically.
Usage
Once Dynamic Asset Versioning is active, it will automatically determine version numbers based on file modification time for any [non-core] files that have been enqueued using wp_enqueue_style() or wp_enqueue_script().
Example
wp_enqueue_style(
'my-theme-styles',
get_template_directory_uri() . '/assets/css/my-styles.css',
array( 'some-other-styles' ),
false, // Don't worry about it, Dynamic Asset Versioning has you covered!
'screen'
);

Special thanks
A special thanks goes out to 10up, who helped inspire the original concept of this plugin.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon