It makes the debugging process hard.
If the project contains some bug and you fix it but the user needs to clear the browser cache to reflect the changes.
1. Separate File
- Include the created script file in your file.
2. Random String
Add a random string to
src attribute while including the script in your file.
You need to update the version value each time you made changes to the code.
Each time when a page is loaded then browser view it as a new file and load it.
3. Dynamically Change version
If you are using the Server side script in your project e.g. PHP then you can make it dynamic and don’t need to update the value each time when you modify the file.
<script src='script.js?version=<?= time() ?>'></script>
I have added PHP
time() function to make random string value unique you can also use a
<script src='script.js?random=<?= uniqid() ?>'></script>
If you are using Server-side scripting in your project then it is better to make custom string value dynamic instead of updating it manually.