Skip to content

Instantly share code, notes, and snippets.

@mrhammadasif
Created July 28, 2020 13:34
Show Gist options
  • Save mrhammadasif/7d630bcbd0b377203cd6b1ae6dae336f to your computer and use it in GitHub Desktop.
Save mrhammadasif/7d630bcbd0b377203cd6b1ae6dae336f to your computer and use it in GitHub Desktop.
Version Management for Vue SPA application to see for outdated content
import compareVersions from 'compare-versions';
fetch(process.env.BASE_URL + `version.json?_d=` + encodeURI(new Date().toJSON()), {
method: "GET",
headers: {
"pragma": "no-cache",
"cache-control": "no-store"
}
})
.then(resp => resp.json())
.then(json => {
console.log("Server Version: " + json.version)
console.log("Local Version: " + document.head.querySelector("[name=version]").attributes['content'].value)
if (compareVersions(json.version, document.head.querySelector("[name=version]").attributes['content'].value) != 0) {
confirm("You are using outdated application, from cache. Do you want to reload the latest version from server?")
}
})
.catch(e => console.error('Unable to compare version from server'))
// add this library for comparing versions
// yarn add compare-versions
require("./check-version")
{
"name": "<%= package.name %>",
"buildDate": "<%= currentTime %>",
"version": "<%= package.version %>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment