11

Summary

Create a cache busting feature to ease deployment and testing, and create a local data store to hold database content on the web server.

Overview

Purpose Modify website to avoid using stale CSS, JavaScriptA language that can run in the browser to make websites interactive., and image files cached in the browser.  Improve site responsiveness and reduce cost by using a local store to hold database table contents.
Goals
TechnologyNo new additions to environment.
ResourcesNone

Implementation

  1. Add File Versioning Function

    Modify /Core/View.php to:
    • Add fileTimestamp Function - Returns the last updated timestamp of the file identified by the given link, returns null if the file is not found.
    • Add versionedLink Function - Returns the given link with the last updated timestamp included in the file name, returns the link unchanged if no timestamp is found.
    • Add addVersioning Function - Returns the HTML of the given page replacing the local links with ones containing the last updated timestamp where possible.
    • Modify renderTemplate Function - Applies the addVersioning function to the HTML prior to returning it to the calling function.
  2. Modify URL Rewrite Rules

    Modify /public/.htaccess to add a new rewrite rule to remove the versioning added to CSS, JavaScriptA language that can run in the browser to make websites interactive. and image files:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.[\d]{14}\.(css|js|png|jpeg|jpg)$ $1.$2

  3. Create Site Source Variable

    This variable controls whether the data is pulled from the database or from the local store:
    • Add Environmental Variable - edit the httpd.conf to add a SITE_SOURCE variable which can be set to either DATABASE or LOCAL.
    • Modify Config Class - Add getSiteSource function to the App/Config.php to access and return the value of the environmental variable.
  4. Create Store Files

    • Create Store Directory - Store was created at the Document Root.
    • Modify Editor Controller Class - add a saveLocalArray function to App/Controller/Editor.php to write all records in the FACT_CONTENT table to the Store/content.json file. This data is an array of JSON objects. The function is called every time the "Push to Database" option is clicked in the editor to save changes to a page.
    • Modify Search Controller Class - add a saveLocalArray function to App/Controller/Search.php to write all records in the FACT_SEARCH table to the Store/search.json file. The function is called when the "Purge and Reload Search Statistics" is clicked on the Administration page.
  5. Modify Model Classes

    • Modify Content Model Class - add pullAll function to supply data to the Editor's saveLocalArray function. Create two versions of the functions that retrieve data, a database and a local version (e.g. for getById there is now databaseGetById and localGetById). The original function uses the Site Source to determine which of the two versions of the function to use. The local versions use the Store/search.json and filters the array to return the requested results.
    • Modify Search Model Class - add pullAll function to supply data to the Search Controller's saveLocalArray function. Similar to the Content Model, two versions of the functions that retrieve data were created, a database and a local version and the Site Source is used to determine which to call.
  6. Add Content Store Refresh to Administration Page

    Modify /App/Views/Admin/index.html to add a button to trigger a refresh of the Content store file.
  7. Remove Carriage Returns

    • Modify /public/js/tbd-editor.js - to strip out carriage returns and line feeds from Content and Script fields before saving to a file or to the database.
    • Update Content Table - run update commands against the Content table to remove the carriage returns and line feeds from all records:

      UPDATE fact_content set content_txt = replace(content_txt, '\r\n', '');
      UPDATE fact_content set script_txt = replace(script_txt, '\r\n', '');

  8. Relocate Javascript Directory