DEV Community

Discussion on: Can you please refresh (Or how we version our Single-Page Application)

Collapse
 
originalexe profile image
Ante Sepic • Edited

Hi,

This app did not make use of service workers, so we did not have to implement any workarounds. Since the headers on Cloudfront were set so that html files were never cached, there were never any cache-related problems.

Also if possible could you share the function isNewerVersionAvailable()

I have since changed jobs so I no longer have access to the source code, but the logic was something like:

let oldSource = null;

async function isNewerVersionAvailable() {
  const freshSource = await fetch(...);

  if (oldSource === null) {
    oldSource = freshSource;
    return false;
  }

  if (oldSource === freshSource) {
    return false;
  }

  oldSource = freshSource;
  return true;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gauravvermamaropost profile image
gaurav-verma-maropost

Thanks. Just one question why didn't you considered calling some other smaller file's response headers time stamp by fetching that one. That could have saved some data per request.

Thread Thread
 
originalexe profile image
Ante Sepic

The fact is that our HTML file was already rather small (2.57kb gzip), so while fetching for example just file headers would have been less expensive in terms of bandwidth, I think we were rather happy with that approach. If I were to do it again, I would test the headers approach and go with that if it was equally reliable.

Collapse
 
dillon profile image
dillon

Was the edge-case of the first request being a new version considered? Seems like a user could potentially miss out on a notification for an entire version if their first page load is within the 10 minute interval of a new version being deployed.

I suppose a workaround could be just setting oldSource ASAP after first page load which cuts the edge-case window down drastically.