
內容簡介
您是一位前端開發人員嗎?想要清除所有使用者的瀏覽器快取嗎?只需啟用此外掛程式並展現您的作品!
Prevent Browser Caching 外掛程式可讓您自動或手動一鍵更新所有 CSS 和 JS 檔案的資產版本。
現在,您可以在不要求客戶清除快取的情況下展示網站上的最新更改。
它如何運作?
通常情況下,WordPress 使用 query 參數 “ver” 在 URL 中載入資產(例如,style.css?ver=4.9.6)。這使得瀏覽器可以將這些資產快取,直到該參數更新。
為了防止 CSS 和 JS 檔案快取,此外掛程式會為所有使用 wp_enqueue_style 和 wp_enqueue_script 函式載入的鏈結加上唯一的編號(例如,style.css?ver=4.9.6.1526905286)到 “ver” 參數。
針對開發人員
預設情況下,此外掛程式將在每次使用者載入頁面時更新所有資產檔案,並在管理面板中(設定→ Prevent Browser Caching)新增選項,以讓您配置這些檔案的更新。
您也可以以程式的方式設定 CSS 和 JS 檔案的版本。
只需將此程式碼插入您的佈景主題的 functions.php 檔案中,並在需要更新資產時更改 assets_version 值:
prevent_browser_caching( array(
'assets_version' => '123'
) );
外掛標籤
開發者團隊
原文外掛簡介
Are you a frontend developer? Do you want to clear browser cache for all users? Just activate this plugin and show your work!
Prevent Browser 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., 1526905286) to the “ver” parameter (e.g., style.css?ver=4.9.6.1526905286) 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 -> Prevent Browser 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:
prevent_browser_caching( array(
'assets_version' => '123'
) );
