RU
RukshanRanasinghe2000/auto-reload-static-websites-JS
Auto reload when content changes of static website
auto-reload-websites-JS
Auto reload when content changes of website
Auto Reload on New Deployment
This project includes a simple script that automatically reloads the webpage when a new version of the site is deployed, without requiring user interaction.
How It Works
The following JavaScript function uses setInterval() to periodically check a version.txt file. If the content of that file changes (indicating a new version of the site), the page is reloaded automatically.
How to use
- Place auto-refresh.js and version.txt in your project folder, typically, the JS file is placed in a js or scripts directory and version.txt file placed in root directory.
- Link it in your HTML file where the auto-refresh behavior is needed.
Recomendations
- Do not link this JS file as a critical script in the section, as it can lead to performance issues.
- Instead, link this JS file in the HTML where needed and add the
deferattribute to the <script> tag to ensure it doesnt block HTML parsing.
ex:-<script src="auto-refresh.js"defer></script> - This function is usefull when you are developing
- Static Websites (HTML, CSS, JS).
- Single Page Applications and Marketing & Product Pages without using frameworks or build tools.
Benifits
- No need for manual page refresh
- No external libraries or build tools (like npm)
- Simple, lightweight solution
On this page
Contributors
Created April 13, 2025
Updated December 14, 2025