GithubHelp home page GithubHelp logo

matthewpennell / mgp.ee_cachebuster.ee_addon Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 80 KB

Force browsers to download new versions of static CSS and JavaScript files

Home Page: http://www.thewatchmakerproject.com/blog/new-expressionengine-extension-cachebuster/

mgp.ee_cachebuster.ee_addon's Introduction

MGP Cachebuster – Force your visitor’s to download the latest version of stylesheets and script files (ExpressionEngine extension).

Author: Matthew Pennell – Principal, 29digital

GitHub Repository: http://github.com/matthewpennell/mgp.ee_cachebuster.ee_addon/

Documentation

A full explanation of this extension can be found at http://www.thewatchmakerproject.com/blog/new-expressionengine-extension-cachebuster/

Installation

As this extension relies on hacking the core EE files, it is NOT recommended for mission-critical sites or applications. However, if you are confident that you can maintain the necessary hack (including when upgrading) you shouldn’t have any problems. (If you forget to upgrade, the extension will fail silently.)

Hacking a new hook

Open the /system/core/core.output.php file and locate the following lines (around line 272 in EE1.6.5):


/* -————————————————
/
* Fetch the buffered output
/* -————————————————/

echo $output;

We are going to add a new hook for our extension to allow us to manipulate the HTML output just prior to sending it to the browser. Add the new lines shown below:


/* -————————————————
/
* Fetch the buffered output
/* -————————————————/

// MGP Cachebuster 030209: Added new hook to do stuff with the final browser output
if (isset($EXT→extensions[‘before_display_final_output’]))
{
$output = $EXT→call_extension(‘before_display_final_output’, $output);
}

echo $output;

We also need to make sure we can refer to the $EXT object – scroll up to the start of the display_final_output() function (around line 94) and add $EXT to the declared globals on the first line of the function:

global $IN, $PREFS, $TMPL, $BM, $DB, $SESS, $FNS, $LOC, $EXT;

Installing the extension

Installing the Cachebuster extension is exactly the same as installing any other extension:

  1. Copy the ext.cachebuster.php file into /system/extensions
  2. Copy lang.cachebuster.php into /system/language/english
  3. Visit your Extensions Manager and enable the new extension

Using the Cachebuster

When you visit the Settings page for the Cachebuster extension, you will see five fields:

  • Current version – This is the version number that will be appended to CSS or JS files to force visitors to load the latest version instead of a cached version
  • Apply version numbers to CSS files – Choose whether you want to control CSS files
  • CSS filenames – A comma-separated list of stylesheets you want to affect (either with or without the “.css” extension)
  • Apply version numbers to JavaScript files – Choose whether you want to control JavaScript files
  • JavaScript filenames – A comma-separated list of external scripts you want to affect (either with or without the “.js” extension)

Every time you make a change to a CSS or JavaScript file and upload it to the live website, you want to be sure that visitors are getting that new version of the file and not a cached one (especially if older versions of the file will cause layout or functionality bugs). This extension appends a querystring parameter to each file flagged in the settings, which causes the browser to treat it as a new file and ignore any cached versions.

License

MGP Cachebuster is currently available for use in all personal or commercial projects under Creative Commons Attribution-Share Alike 3.0 Unported license.

You are free to:

  • Share – to copy, distribute and transmit the work
  • Remix – to adapt the work

Under the following conditions:

  • Attribution – You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
  • Share Alike – If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.

mgp.ee_cachebuster.ee_addon's People

Contributors

matthewpennell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.