Forums

a few users not seeing an updated javascript file

Hi,

I am wondering if you can help understand what i need to do differently. My understanding of the issue is marginal so the details below maybe confused.

background info

  • it's flask based web app, feel free to look at the code.
  • the code sets this flask param: ( i am thinking this tells client browser to always fetch the js files) app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 (all the get static files have the Cache-Control set)
    • before rq: GET, static, ......./static/js/dupsTab.js
    • after rq: Cache-Control: no-cache, max-age=0
  • the pyAny static files config param is set to: /static/ /home/[username]/mysite/static/

issue

  • I updated a client javascript api call with an additional param, 'durTimeDiff', to send with the post request to the server.
  • Most users automatically get the new javascript file and everything works well.
  • But occasionally i see a error in the logs indicating a user is still using the old version of the javascript file.
  • the error indicates the newly added, 'durTimeDiff' in dupsTab.js , param is missing
  • 2023-03-12 17:18:18,625: Exception on /Tabs [POST]
  • Traceback (most recent call last):
  • File "/home/[username]/mysite/[app fn].py", line 278, in Tabs
    • durTimeDiff = rqJson['durTimeDiff']
  • one user emailed about the error and i replied with clear your browser's cache and that appears to have the issue.

observation:

  • the access log seems to indicate that user gets all the js/css files when they go to the site.

questions

  • why are a just few users failing to get the updated js file, when the vast majority get the updated js file?
  • do you have any thoughts on what i need to do?

Hopefully this makes sense and thank you, Louie

The users that are getting the older file have more aggressive caching or they have not reloaded the page that loads the javascript file so it has just been sitting in their browser for a while.

Hi Glenn,

  • i agree not reloading the site after the js file update would generate the error.
  • one of the users that had this issue reported getting the error after multiple reloads in multiple browsers
  • so it would seem this user did a reload

Question

  • would adding the following make any sense as a fix?
  • @app.after_request
  • def add_header(response): - response.headers['Cache-Control'] = 'no-store, no-cache, max-age=0 '
    • return response

Question

  • is it possible that a intermediate cdn is caching the old js file?

Louie

Hi Louie. It should fix the problem of the client's browser caching the old file (and might also affect CDN caching), but it could also have performance implications. Maybe you could version your js code to force an update?

thanks for the reply...there is just no way to avoid taking a deep dive on this so i have started digging into this by reading articles and stack exchange posts. Yes you are right it would be best to use versioning to reduce network traffic and improve performance. I am curious which form of versioning are you referring to 1 or 2?

1) Versioning: add a version number to the filename:

  • assets/js/app-v2.min.js

2) Append Query String: append a query string to the end of the filename:

  • assets/js/app.min.js?version=2

I was thinking of option 2, but it's just a matter of your preference :)