Created
July 28, 2020 13:34
-
-
Save mrhammadasif/7d630bcbd0b377203cd6b1ae6dae336f to your computer and use it in GitHub Desktop.
Version Management for Vue SPA application to see for outdated content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this library for comparing versions | |
// yarn add compare-versions | |
require("./check-version") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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