Jump to the post that solved this thread.
Solved: 6 Years, 4 Months, 3 Weeks ago Whats the purpose of query strings on javascript?
#1
Solved: 6 Years, 4 Months, 3 Weeks ago
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/general.js?ver=1817"></script>

What's the purpose of having ?ver=1817 attached, other than indicating the version ? Does the codebase call this anywhere ?

And as a suggestion, why not indicate version included in the URL?

<script type="text/javascript" src="{$mybb->asset_url}/jscripts/general-1817.js"></script>

What's the effect of dropping the query string ?

<script type="text/javascript" src="{$mybb->asset_url}/jscripts/general.js"></script>

or

<script type="text/javascript" src="{$mybb->asset_url}/jscripts/general.min.js"></script>
What goes around comes around
Reply
#2
Solved: 6 Years, 4 Months, 3 Weeks ago
You can drop it for sure and it will work as intended.
The reason it is appended there is to handle browser cache. Sometimes the browser keeps the cached resources and upon same request returns the resource from cache instead of repeatedly downloading it from the source to optimize bandwidth and page load time.

This can lead to the problem as say if you have the general.js cached by the browser in v. 1.8.15 and you have been upgraded to v. 1.8.17. Now say there is a big change in general.js in 1.8.17 upgrade. What the browser get is a request to include general.js from the same source defined earlier. Browser has no clue that the current resource has been changed with the upgrade and returns the resource from the cache which is actually a copy of general.js that was included with 1.8.15 and hence the resource doesn't contain the updated code. This can break your site / lead to unintended behavior. Appending the version differs the resource ink from earlier so browser now knows that this is a different resource from it was earlier, hence re-downloads and re-caches it. Thus you always get the latest resource included in your page avoiding the said issue.

The good practice is to include the file hash instead of version in query string as the hash gets changed only if the file is changed. But for us this suffice the purpose as it is now.
Reply
#3
Solved: 6 Years, 4 Months, 3 Weeks ago
Thanks.
What goes around comes around
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)