Sage CRM 2023 R2: Adding a query string to a script reference to prevent Caching

1 minute read time.

I wonder if you have ever looked at the viewed the page source of a screen in Sage CRM and seen this...

The script reference looks like src="/[instance]/js/crm/Z010_crmAPICore.js?version=xxxx".

This is a trick used by of our developers.  By adding a query string to a script reference prevents caching and ensures loading of the latest version of the library file.

Browsers store previously loaded files in a cache to improve loading speed on subsequent visits.

When a script is referenced again, the browser checks its cache first.

Adding a query string (e.g., ?xxxx) to the script's URL creates a unique URL, even if the underlying file name is the same.
This tricks the browser into thinking it's a different file, preventing it from using the cached version.

Sage CRM could use any random string can be used as a query parameter, not just integers but it is convenient to link this to our internal build versions.

The browser compares the full URL, including the query string, with its cached resources. If a match is not found, it fetches the file from the server. This ensures users always have the most recent version of the script, even if they've visited the page before.

This means that changes to the script take effect immediately, without users needing to clear their cache.

This trick is widely supported by modern browsers, including Chrome, Firefox, Safari and Edge.