User:Manishearth/purger

From Wikipedia, the free encyclopedia

This script is a lightweight cached script purger for developers. It saves developers time and bandwidth when testing scripts by forcing the browser to purge selective scripts (set through a cookie), so that you don't have to download the entire page, js, css, and images.

Instructions to install[edit]

All Imports should go there, even ones you don't want purged. This is necessary for it to work. See explanation below
  • Completely purge your cache

How to use[edit]

In the "toolbox" in the sidebar, there'll be a link "Purge scripts". You will get a prompt with the current purged scripts in it (By default it'll be empty). To add more scripts, just type their path (e.g. User:Foo/bar.js), and separate them by commas (Actually you don't need to separate them, but I kept this for uniformity :) )
All scripts stored in the cookie (Modified through aforementioned "Purge scripts" button) will be forcibly fetched from the server every time you reload any page on Wikipedia.


Note: If you remove a script from the list, your browser may revert to an older, unpurged version, so it's always better to clean your cache after you finish testing a script and want to go back to normal editing.
importScriptPurged() forces a script to be purged without reading the cookie.
importScriptPurged(seed) purges the script to seed (seed is any integer). For example, if you want the script to be purged once a day, keep the date as the seed, so the script will only be purged when the date changes. This function is useful when you don't want to have to download scripts on every single page load.

Why all of your imports need to be in imports.js[edit]

The script purges only the scripts which are stored in a certain cookie set by the aforementioned "Purge scripts" button.
It does not purge all scripts in imports.js. This script modifies the importScript() function, so all imports must be in imports.js. ADD ALL IMPORTS THERE, even ones you don't want purged currently. This script will purge the scripts in the cookie and no more. The imports.js subpage is only so that the imports are executed after this script is executed. All changes to the imports.js page will go live immediately, as the page is force purged.

How this script works[edit]

importScript() is wikipedia function which imports a script with a URL somewhat like this . In normal conditions, your browser will cache the script and map it with the same URL. This script modifies importScript() so that it appends a random parameter "&rand=random number" to make the link like this. The browser recognizes this as a new script, though it is the same script. The random tail will only be appended to the script if the script name is somewhere in the cookie.