Notifications

8 views

Description

Description


Image files are cached automatically by the browser for perfromance reasons.

If you have a UI Page that displays an image coming from the db_image table using the following HTML you will get the browser cached version of the file logo.png:

<img src="logo.png" width="175" height="148"/> 

If the image is updated in the db_image table you will still get the cached file until the user refreshes the browser's cache.

This is not really a ServiceNow specific issue but related to how browser caching works.

 

Procedure


There is a way to modify the above HTML tag to ensure the latest version of the image file is always displayed on the UI Page.

The following discussion addresses the same issue: 
https://stackoverflow.com/questions/1431512/is-there-a-way-to-force-browsers-to-refresh-download-images 

From the above page, one way to ensure that the browser always downloads the latest version of the file is to append the filename with "?<unique number or timestamp>".


The solution would be to use following code modification in the UI Page script:
 
<img src="logo.png?${gs.nowDateTime()}" width="100" height="100"/> 

This will always add the current timestamp to the name of the file requested and as it will always be unique the file will always be downloaded from the server and ignore anything that is already in the browser cache.

 

Applicable Versions


All versions

 

Additional Information


It should be noted there could be a slight performance impact because: 
- there is a function call in the UI Page. 
- the image file would be downloaded from the server every time the UI Page is viewed. 

Article Information

Last Updated:2019-08-02 20:51:33
Published:2019-02-21