Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding cache buster to index.html #445 #451

Merged
merged 10 commits into from
Dec 28, 2023
20 changes: 20 additions & 0 deletions cacheBuster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// cacheBuster.ts
function generateCacheBuster(): string {
// Find the main.ts script tag and remove it
const mainScript: HTMLScriptElement | null = document.querySelector('script[src*="main.ts"]');
if (mainScript) {
mainScript.remove();
}
shech2 marked this conversation as resolved.
Show resolved Hide resolved
// Generate a cache buster value based on the current timestamp
const currentTimestamp: number = Math.floor(Date.now() / 1000);
// Divide by 3600 to create a cache buster value that updates every hour
const cacheBusterValue: number = Math.floor(currentTimestamp / 3600);
return `?v=${cacheBusterValue}`;
}

// Set the src attribute for main.ts script
const script: HTMLScriptElement = document.createElement('script');
script.type = 'module';
script.src = `/main.ts${generateCacheBuster()}`;
document.head.appendChild(script);
shech2 marked this conversation as resolved.
Show resolved Hide resolved

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,6 @@ <h1><span class="name"></span> Error</h1>
arrow_2_circlepath</i></button>
</nav>
</template>
<script type="text/javascript" src="/cacheBuster.ts"></script>
shech2 marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
Loading