After looking at some HTML sourses, I found some "meaningless" file inclusion, for both css and js.
I call this "meaningless" because,
<script src="some_file.js?123"></script> ALWAYS TOTALY EQUALS (size in bytes) TO
<link href="some.css?var=val" rel="stylesheet" type="text/css" /> === the same as aforementioned.So the question is, Why people use this? Wnen to/not to use this?
Thanks.
This is usually done to prevent the browser from caching static files.
The query part might be used to prevent caching as WojtekT suggests (whether that’s successful or useful is a different issue), but it can also be used to pass data to the process that generates or serves the resource. For example, some.css?var=rel may cause a different version of a style sheet, or completely different style sheet, to be generated than some.css. The parameter could be used e.g. to pass user options (perhaps clumsier than cookies or HTML storage, but still possible).
Your assumption 3 is wrong in two ways. First, common client-side technology (client-side JavaScript) can easily process GET variables. Second, this isn’t about client-side. The reference some.css?var=val is processed by the browser to construct an absolute URL, keeping the query part, and then to generate a GET request to the server (passing the query part along), unless it finds out that the resource is in the browser’s cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With