File Auto-Versioning for Zen Cart v1.5.4 (and later)

Version 1.0.0 by lat9. Copyright © 2017, Vinos de Frutas Tropicales

Current Support Thread at Zen Cart Forums: https://www.zen-cart.com/showthread.php?221658-File-Auto-Versioning-Support-Thread

Starting with Zen Cart® 1.5.2, additional rules have been added to your store's /includes/.htaccess instructing the customer's browser to cache images, PDFs, CSS and javascript files for certain periods. While that caching provides your site with a performance "boost", it's not without cost … what happens if you've added a plugin that adds some styling to your current template's stylesheet.css? The short answer is that until the customer specifically refreshes their browser or clears their browser's cache (possibly multiple times), those changes won't be pulled from your site because the browser has been told to cache that file's contents!

That's where File Auto-Versioning comes into play. You can use this plugin to add a version string to those file "assets" so that your customers' browsers are always pulling in the most recent content.

The plugin uses a file's last-modified date as its associated version string, changing
<link rel="stylesheet" type="text/css" href="includes/templates/vinos_rc/css/stylesheet.css" />
to
<link rel="stylesheet" type="text/css" href="includes/templates/vinos_rc/css/stylesheet.css?1479138764" />

When that stylesheet.css file is updated, its version-string will change and result in the browser now caching that updated content since the link to the file has changed.

This section identifies the procedure you'll use to install or remove the plugin for your Zen Cart.

This plugin's installation requires you to change your current template's /common/html_header.php file to introduce the changes. The plugin's distribution contains three (3) files:

  1. /includes/functions/extra_functions/vinos_file_auto_versioning.php. (This file is specific to this plugin)
  2. /includes/templates/YOUR_RESPONSIVE_TEMPLATE/common/html_header.php. (This is the like-named file from the Zen Cart 1.5.5d release's responsive_classic template, with the plugin's changes applied 11 times)
  3. /includes/templates/YOUR_TEMPLATE/common/html_header.php. (This is the like-named file from the Zen Cart 1.5.5d release's template_default template, with the plugin's changes applied 7 times)

Each of those html_header.php files has been updated to make use of the vinosFileAutoVersioning function for the .css and .js files included in the current page's load.

To install File Auto-Versioning:

  1. Copy the function-file to your store's /includes/functions/extra_functions directory.
  2. Edit/merge the changes required into your current template's copy of /common/html_header.php.

Restore any files to which you've added the vinosFileAutoVersioning function to their prior state; then it's safe to remove the function-file provided with this plugin.

This section identifies the files added or modified for this plugin as well as the plugin's change history.

The plugin provides the following files in its distribution zip-file.

  1. /includes/functions/extra_functions/vinos_file_auto_versioning.php
  2. /includes/templates/YOUR_RESPONSIVE_TEMPLATE/common/html_header.php
  3. /includes/templates/YOUR_TEMPLATE/common/html_header.php
  • v1.0.0, 2017-01-04:
    • Initial release.