Ensure Users Are Running Latest JavaScript

Overview

What Is It?

When making JavaScript changes, ensure the changes are placed in a new filename. The current naming standard is basename_YYYYMMDD.js.

Browsers, by default, attempt to cache JavaScript and stylesheet files. As we change JavaScript to support new features, it is important that the latest JavaScript is downloaded to the users' browser. Since our users can be on their own computers, we can’t force a clearing of their browser cache.

By deploying new names for each changed JavaScript file, the browser sees these as new files and downloads them.

How Does It Work?

The header specifies a new framework file so the browser downloads it and caches the new version. The framework specifies new names for the base JavaScript files so the browser downloads those as well. The user's browser is always running your latest JavaScript code.

Administration

ClosedComponent 1: Base JavaScript Files

For each release, copy the latest base JavaScript file (commerce, config, commerce_line, homepage, and so on) into a new file with the basename + _ + RELEASEDATE.


ClosedComponent 2: JavaScript Framework

The JavaScript framework (bm-framework.js) loads all necessary JavaScript files (commerce, config, homepage, and so on). When you change one of the underlying files, you need to update the framework to pull in the correct version.

Create a new version of the framework with the naming standard bm-framework-YYYYMMDD.js.

setup.pages = {
homepage_20130323: {
active:true
},
commerce_20130720: {
active:true
},
commerce_line_20130622: {
active:true
},
config_20130622: {
active:true
},
sitewide: {
active:true
}
};

ClosedComponent 3: HTML Header

The HTML Header loads bm-framework.js. This needs to change with each release, to bring in the appropriate framework.


ClosedHow To Use It

  1. Copy latest version of base javascript file (for example, commerce_20130622.js) to a new release date
  2. Make appropriate changes.
  3. Copy the latest framework file (for example, bm-framework_20130622.js) to a new release date.
  4. Update the setup.pages section of the new bm-framework to pull in the latest base file.

Notes

  • During the release, any future changes to the base files won’t automatically download since the new release date versions are cached for your development team. The development team needs to force a cache refresh. This will not be the case for your production users as the final version will be released at go live.
  • You can periodically delete older versions of your JavaScript files.
This solution uses JavaScript. This should only be adopted if you have a strong technical team.

Related Topics

Related Topics Link IconSee Also