Yang
Yang

Reputation: 8701

src="some.js?var=val" what does it actually mean?

After looking at some HTML sourses, I found some "meaningless" file inclusion, for both css and js.

I call this "meaningless" because,

  1. <script src="some_file.js?123"></script> ALWAYS TOTALY EQUALS (size in bytes) TO
  2. <link href="some.css?var=val" rel="stylesheet" type="text/css" /> === the same as aforementioned.
  3. As we know, usually client-side technology can't parse vars which are coming from HTTP (mean from POST and GET), this job for server-side one.

So the question is, Why people use this? Wnen to/not to use this?

Thanks.

Upvotes: 2

Views: 143

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

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

WojtekT
WojtekT

Reputation: 4775

This is usually done to prevent the browser from caching static files.

Upvotes: 6

Related Questions