A
A
asdz2014-10-03 14:53:40
PHP
asdz, 2014-10-03 14:53:40

How to update the js file on the client if it has changed on the server?

When developing a web application, after the next change in js files, cached versions remain on the clients, which causes errors. Not all users know when and how to clear the cache. How to make sure that when updating js files on the server, clients download updated files and do not use outdated versions in the local cache.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Gontarenko, 2014-10-03
@asdz

<script src="js/file.js?<?=filemtime( 'js/file.js' )?>" />

best file change time

A
asdz, 2014-10-03
@asdz

I found a good solution to embed the md5 hash of the file in the URL of the link, when the file changes, the hash will change and the file will be downloaded by the client. stackoverflow.com/questions/118884/what-is-an-eleg...

U
ultrabi4, 2014-10-03
@ultrbi4

add file version
<script src="js/main.js?v2.01">

D
Dmitry, 2014-10-03
@CTAKAH4uK

The easiest way to add salt to script loading is:

<script src="script.js?<?=rand()?>" type="text/javascript"></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question