mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
feat: use StaleWhileRevalidate for scripts poloicy; v1.104.2
This commit is contained in:
parent
d3ba6dd95b
commit
3d1f268003
5 changed files with 33 additions and 40 deletions
|
|
@ -1990,8 +1990,8 @@
|
|||
</button>
|
||||
<button
|
||||
id="optionsReset"
|
||||
data-tip="Click to restore default options (page will be reloaded)"
|
||||
onclick="restoreDefaultOptions()"
|
||||
data-tip="Click to restore default options and reload the page"
|
||||
onclick="cleanupData()"
|
||||
>
|
||||
Reset to defaults
|
||||
</button>
|
||||
|
|
|
|||
5
main.js
5
main.js
|
|
@ -666,10 +666,7 @@ async function generate(options) {
|
|||
title: "Generation error",
|
||||
width: "32em",
|
||||
buttons: {
|
||||
"Clear data": function () {
|
||||
localStorage.clear();
|
||||
localStorage.setItem("version", VERSION);
|
||||
},
|
||||
"Cleanup data": cleanupData,
|
||||
Regenerate: function () {
|
||||
regenerateMap("generation error");
|
||||
$(this).dialog("close");
|
||||
|
|
|
|||
|
|
@ -703,12 +703,6 @@ async function openTemplateSelectionDialog() {
|
|||
HeightmapSelectionDialog.open();
|
||||
}
|
||||
|
||||
// remove all saved data from LocalStorage and reload the page
|
||||
function restoreDefaultOptions() {
|
||||
localStorage.clear();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
// Sticked menu Options listeners
|
||||
byId("sticked").addEventListener("click", function (event) {
|
||||
const id = event.target.id;
|
||||
|
|
|
|||
9
sw.js
9
sw.js
|
|
@ -1,7 +1,7 @@
|
|||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
|
||||
|
||||
const {Route, registerRoute} = workbox.routing;
|
||||
const {CacheFirst, NetworkFirst} = workbox.strategies;
|
||||
const {CacheFirst, NetworkFirst, StaleWhileRevalidate} = workbox.strategies;
|
||||
const {CacheableResponsePlugin} = workbox.cacheableResponse;
|
||||
const {ExpirationPlugin} = workbox.expiration;
|
||||
|
||||
|
|
@ -18,8 +18,11 @@ registerRoute(
|
|||
|
||||
registerRoute(
|
||||
({request, url}) =>
|
||||
request.destination === "script" && !url.pathname.endsWith("min.js") && !url.pathname.includes("versioning.js"),
|
||||
new CacheFirst({
|
||||
request.destination === "script" &&
|
||||
!url.pathname.endsWith("min.js") &&
|
||||
!url.pathname.includes("versioning.js") &&
|
||||
!url.contains("google"),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: "fmg-scripts",
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({statuses: [0, 200]}),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
||||
*/
|
||||
const VERSION = "1.104.1";
|
||||
const VERSION = "1.104.2";
|
||||
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
||||
|
||||
{
|
||||
|
|
@ -21,7 +21,9 @@ if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format o
|
|||
if (loadingScreenVersion) loadingScreenVersion.innerText = `v${VERSION}`;
|
||||
|
||||
const storedVersion = localStorage.getItem("version");
|
||||
if (compareVersions(storedVersion, VERSION, {patch: false}).isOlder) setTimeout(showUpdateWindow, 6000);
|
||||
if (compareVersions(storedVersion, VERSION, {major: true, minor: true, patch: false}).isOlder) {
|
||||
setTimeout(showUpdateWindow, 6000);
|
||||
}
|
||||
|
||||
function showUpdateWindow() {
|
||||
const changelog = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog";
|
||||
|
|
@ -34,7 +36,7 @@ if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format o
|
|||
|
||||
<ul>
|
||||
<strong>Latest changes:</strong>
|
||||
<li>Style: ability to set letter spacing</li>
|
||||
<li>Labels: ability to set letter spacing</li>
|
||||
<li>Zones update</li>
|
||||
<li>Notes Editor: on-demand AI text generation</li>
|
||||
<li>New style preset: Dark Seas</li>
|
||||
|
|
@ -44,41 +46,38 @@ if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format o
|
|||
<li>Preview villages map</li>
|
||||
<li>Ability to render ocean heightmap</li>
|
||||
<li>Scale bar styling features</li>
|
||||
<li>Vignette visual layer and vignette styling options</li>
|
||||
</ul>
|
||||
|
||||
<p>Join our <a href="${discord}" target="_blank">Discord server</a> and <a href="${reddit}" target="_blank">Reddit community</a> to ask questions, share maps, discuss the Generator and Worlbuilding, report bugs and propose new features.</p>
|
||||
<span><i>Thanks for all supporters on <a href="${patreon}" target="_blank">Patreon</a>!</i></span>`;
|
||||
|
||||
const buttons = {
|
||||
Ok: function () {
|
||||
$(this).dialog("close");
|
||||
localStorage.setItem("version", VERSION);
|
||||
}
|
||||
};
|
||||
|
||||
if (storedVersion) {
|
||||
buttons.Cleanup = () => {
|
||||
clearCache();
|
||||
localStorage.clear();
|
||||
localStorage.setItem("version", VERSION);
|
||||
location.reload();
|
||||
};
|
||||
}
|
||||
|
||||
$("#alert").dialog({
|
||||
resizable: false,
|
||||
title: "Fantasy Map Generator update",
|
||||
width: "28em",
|
||||
position: {my: "center center-4em", at: "center", of: "svg"},
|
||||
buttons
|
||||
buttons: {
|
||||
"Cleanup data": () => cleanupData(),
|
||||
"Don't show again": function () {
|
||||
$(this).dialog("close");
|
||||
localStorage.setItem("version", VERSION);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function clearCache() {
|
||||
const cacheNames = await caches.keys();
|
||||
return Promise.all(cacheNames.map(cacheName => caches.delete(cacheName)));
|
||||
}
|
||||
async function cleanupData() {
|
||||
await clearCache();
|
||||
localStorage.clear();
|
||||
localStorage.setItem("version", VERSION);
|
||||
localStorage.setItem("disable_click_arrow_tooltip", "true");
|
||||
location.reload();
|
||||
}
|
||||
|
||||
async function clearCache() {
|
||||
const cacheNames = await caches.keys();
|
||||
return Promise.all(cacheNames.map(cacheName => caches.delete(cacheName)));
|
||||
}
|
||||
|
||||
function parseMapVersion(version) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue