[WordPress] 外掛分享: Disable Version Caching – Khanakia

首頁外掛目錄 › Disable Version Caching – Khanakia
200+
安裝啟用
★★★★★
5/5 分(3 則評價)
1934 天前
最後更新
問題解決
WordPress 4.0+ v1.0.1 上架:2019-03-28

內容簡介

你是一位前端開發者嗎?你想為所有使用者清除瀏覽器快取嗎?只需啟用這個外掛就可以!

Disable Version Caching 可以自動或手動一鍵更新所有 CSS 和 JS 檔案的資產版本。

現在,你可以在不要求客戶清除快取的情況下,在網站上展示最新更改了。

它是如何運作的?

通常,WordPress 使用 URL 中的查詢參數「ver」(例如style.css?ver=4.9.6)加載資產。這允許瀏覽器將這些檔案快取,直到參數不更新為止。

為了防止 CSS 和 JS 檔案被快取,此外掛將一個獨特的數字(例如 1526903434)添加到「ver」參數中(例如 style.css?ver=4.9.6.1526903434),用 wp_enqueue_style 和 wp_enqueue_script 函式載入的所有鏈結都會進行更改。

針對開發者

預設情況下,此外掛在每次使用者載入頁面時更新所有資產檔案並在管理面板(設定 -> Disable Version Caching)中添加選項,以便您配置這些檔案的更新方式。

但你也可以以程式設定 CSS 和 JS 檔的版本。

只需在你的佈景主題的 functions.php 檔中插入此程式碼,然後當需要更新資產時,變更 assets_version 值:

disable_version_caching( array(
'assets_version' => '123'
) );

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Disable Version Caching – Khanakia」→ 直接安裝(推薦)

原文外掛簡介

Are you a frontend developer? Do you want to clear browser cache for all users? Just activate this plugin and show your work!
Disable Version Caching allows you to update the assets version of all CSS and JS files automatically or manually in one click.
Now you can show the latest changes on the site without asking the client to clear the cache.
How it works?
Usually, WordPress loads assets using query param “ver” in the URL (e.g., style.css?ver=4.9.6). It allows browsers to cache these files until the parameter will not be updated.
To prevent caching of CSS and JS files, this plugin adds a unique number (e.g., 1526903434) to the “ver” parameter (e.g., style.css?ver=4.9.6.1526903434) for all links, loaded using wp_enqueue_style and wp_enqueue_script functions.
For developers
By default, this plugin updates all assets files every time a user loads a page and adds options in the admin panel (Settings -> Disable Version Caching) which allows you to configure updating of these files.
But you can also set the version of CSS and JS files programmatically.
Just insert this code in functions.php file of your theme and change the value of assets_version when you need to update assets:
disable_version_caching( array(
'assets_version' => '123'
) );

延伸相關外掛

文章
Filter
Apply Filters
Mastodon