Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

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.

like image 315
Yang Avatar asked Mar 15 '26 16:03

Yang


2 Answers

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

like image 52
WojtekT Avatar answered Mar 17 '26 04:03

WojtekT


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.

like image 34
Jukka K. Korpela Avatar answered Mar 17 '26 06:03

Jukka K. Korpela