Prevent Browser Caching

外掛說明

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' 
) );

螢幕擷圖

安裝方式

From WordPress dashboard

  1. Visit “Plugins > Add New”.
  2. Search for “Prevent Browser Caching”.
  3. Install and activate Prevent Browser Caching plugin.

From WordPress.org site

  1. Download Prevent Browser Caching plugin.
  2. Upload the “prevent-browser-caching” directory to your “/wp-content/plugins/” directory.
  3. Activate Prevent Browser Caching on your Plugins page.

使用者評論

2022 年 4 月 23 日
Finally a working plugin, which solves the annoying issue of browsers caching old versions of a page!
2022 年 1 月 19 日
Perfect Plugin for developers.
2022 年 3 月 3 日
Works very well when you have a very heavily cached website that is typically frequented by the same users and you have to force a change, this does it so simply right out of the box. Great work! **EDIT** Found that this plugin doesn't play nicely with WooCommerce, so if you plan on using it on your store, make sure to do some sandbox testing to ensure that you are able to complete transactions. We had an issue on a site where it was complaining about the payment type and displaying errors. Once disabled, the site was fine.
2021 年 5 月 24 日
So simple, so effective - I use this on practically every site I manage and it has never caused me any problems. It has saved me so much hassle, irritation, time... and complicated explanations to clients when urgent changes were simply not showing up for them. Such a relief to just click 'Update CSS/JS' (& clear the cache) and everything just works 🙂 BTW, especially valuable when using Elementor, which was previously causing me the most trouble with CSS changes not showing up in the front end -- very occasionally with nested templates/globals I need to refresh all the CSS inside Elementor too, but that's rare. Usually 'Update' on the page and using this plugin is enough.
閱讀全部 23 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈Prevent Browser Caching〉的開發相關工作。

參與者

Prevent Browser Caching 外掛目前已有 5 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將〈Prevent Browser Caching〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

2.3.3

  • Tested the plugin in WordPress 6.1.

2.3.2

  • Fixed “Update CSS/JS” button in the admin bar.

2.3.1

  • Tested the plugin in WordPress 5.1.

2.3

  • Tested the plugin in WordPress 5.0-beta1 and optimized the code.

2.2

  • Added function “prevent_browser_caching” which disables all admin settings of this plugin and allows to set the new settings.
  • Changing “ver” param instead of adding additional “time” param.

2.1

  • Added option to show “Update CSS/JS” button on the toolbar.

2.0

  • Added setting page to the admin panel.
  • Added automatically updating CSS and JS files every period for individual user
  • Added manually updating CSS and JS files for all site visitors

1.1

  • Added plugin text domain.

1.0

  • First version of Prevent Browser Caching plugin.