Message loader script

The loader JavaScript file is a small script that handles where and how each message is displayed. Once active messages are loaded it does the following things for each message:

  • check whether the message is timed or can be displayed immediately
  • check if the message is to be displayed on the current page
  • check if the element to hold the message is found
  • place the message in relation to an element on the page

This functionality is very fast and messages can be displayed almost immediately after page load.

Why are the loader and the messages in separate files?

The main reason for having a separate loader file is page loading speed. The loader is a script that rarely changes and it's also common for all websites that use it. This let's us cache the loader file for long periods of time which avoids transferring it to users on every page load.

The site-specific messages file however changes frequently and needs to update immediately when new messages are added or old ones are activated.

If both files were combined into one, the loader logic would need to be re-downloaded every time the messages changes which if wasteful.