Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does “?”and a number behind after javascript is for?

I saw in some HP code that there is a question mark and a number after javascript file name and it seems like a date or something. What does “?” and a number behind after javascript is for? Example:

<script type="text/javascript" src="/folder/js/folderPageNextSubmit.js?20140801"></script>
like image 960
CDMH Avatar asked Jun 21 '15 05:06

CDMH


2 Answers

it is for cache breaking, for example:

 file.js?1234

 file.js?12345

the browser treats them as two different files, so even if the first one was cached so the second one will be fetched anyway.

you change the number after you do a change in the file code and deploy it, so for the users to see your new changes and load the new file, you change the number.

like image 54
Tzook Bar Noy Avatar answered Nov 10 '22 21:11

Tzook Bar Noy


The "?" in JavaScript or CSS files is a way to add versioning to the file.

Is useful to avoid browser caching when you are working in dev environments because when the versioning number changes, the file URL also changes. So seems to be a different file for the browser.

Is a common practice use a timestamp as versioning number to get something unique but you can use any numbers or chars.

like image 22
ianaya89 Avatar answered Nov 10 '22 20:11

ianaya89