Reputation: 8701
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.
Upvotes: 2
Views: 143
Reputation: 201548
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.
Upvotes: 3
Reputation: 4775
This is usually done to prevent the browser from caching static files.
Upvotes: 6