3

I have seen a code like this and wonder what that curly brackets for, is it some kind of argumant pass?

<script type="text/javascript" src="some_script.js?{0}"></script>
Sarge
  • 388
  • 1
  • 4
  • 22
  • 1
    it's just an http url query argument. you'd have to look at the script itself to see what that argument is being used for (if at all) – Marc B Aug 29 '14 at 14:42
  • 2
    Might you be using a templating engine? It looks like the syntax a templating engine might use. – Kendall Frey Aug 29 '14 at 14:43

3 Answers3

5

In a URL, after the question mark ? is the query string. This is where you specify parameters for the server.

In this case since those brackets aren't encoded (as %7B0%7D), I suspect you're actually seeing this in the context of a template engine, and {0} is a random number. This is commonly used to avoid caching files, since with the random number you effectively have a new URL every time. I don't know what template engine you're using... several use this notation.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • well url also has ?token=xxx so, token as 0th arguman is cached? – Sarge Aug 29 '14 at 14:45
  • 1
    @SercanAltundaş No, every URL has its own cache directives. For static files that you don't want cached and can't control the server response cache headers, it's just a common technique to have a random variable in your URL. `some-static-file.js?0213423423` That way if the server says to cache that file indefinitely, it won't matter because on next load the URL will be `some-static-file.js?88888889`. – Brad Aug 29 '14 at 14:50
  • Thanks a lot, so simply it is a method to avoid static files to be cached. – Sarge Aug 29 '14 at 14:55
  • @SercanAltundaş Yes. But, in the specific case you show in your question, we couldn't possibly know because you didn't tell us what template engine you're using, and what the value of `{0}` is. This is all just a guess based on common practice. For all we know, you might have something setting `{0}` to be a whole query string. – Brad Aug 29 '14 at 14:56
2

it looks like a method to avoid caching by browser. some people do it like this:

<script type="text/javascript" src="some_script.js?timestamp=1235124321"></script>
Peter
  • 16,453
  • 8
  • 51
  • 77
2

There is no special meaning, it is just part of the URL (since it is after a ? it is part of the query string).

Some code (which could be server or client side) might do something with it, but that is specific to the website.

It might be updated programatically to act as a cache busting feature (changing the number changes the URL, so the script would be loaded as a new URL and not as a cached version with a potentially stale script in it).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335