Search code examples
internet-explorercachinggoogle-chrome-extensionfirefox-addonsafari-extension

(How) can I instruct Chrome/Firefox/IE/... not to cache a specific website?


I have built a browser extension that, on startup, calls a web service from which it retrieves a JSON result. The JSON result contains data that will be shown in the popup of the extension. This data is updated at least once a day using a prepared, scheduled update service. Furthermore, the data is irregularly manually updated intra-day.

The data that is retrieved from the web service does not automatically adapt to the changes that are made. Particularly, the extension retrieves old results from the web service. The web service is tested and always returns the newest result, hence this is not a server-side problem (at least not with regards to the computation, storage and provision of the data).

I noticed that sometimes the web service appears to return old results, which then after a page refresh are updated. I believe this happens due to some caching mechanism(s) client- or server-side.

Researching the topic has not yielded any helpful resource or material

Is it possible for me to instruct the extension to not cache results from the web service and/or instruct the server to not allow/serve cached results?

Any advice and/or resource regarding this issue is very much appreciated.


Solution

  • One usual way would be to add a random extension to your HTTP GET path - a parameter, not used by the server. By doing this, the browser cannot use cached data, because it just has not got any for this URL. The server will simply ignore the additional parameter.

    Here is an example, please change the value of the random parameter (12345 in this example) with each call to the server.

    // Original URLs
    http://www.example.com/myservice
    http://www.example.com/myservice?param=data
    
    // With an Additional HTTP Parameter
    http://www.example.com/myservice?random=12345
    http://www.example.com/myservice?param=data&random=12345