0

I often see that 'src' property in script tag has 'arguments/parameters' (I am sorry if I am not using the proper terminology, this is why I am asking). I would like to know:

  1. What is the proper name?
  2. Why is this done this way?
  3. Where is it used?
  4. Is there any advantage by using/doing it this way?

Here it is an example.

<script type='text/javascript' src='root/somedir.js?arg=somevalue'></script>
Gacci
  • 1,388
  • 1
  • 11
  • 23

1 Answers1

1

Basically, it depends of context. And yes, it's called query string.

In some cases it might be used as cache buster (e.g. ?timestamp={current_timestamp}) in order to avoid client-side caching of specified resource.

In other cases it might be used to generate script based on any condition (for example: api key, custom parameter, etc).

Assume you make call to js weather widget, and the documentation says that you should pass the city name as parameter to get the right data, e.g.

<script src="//some-weather-widget.js?city=Sofia"></script>

It's not perfect example, but I think you got the idea.

Community
  • 1
  • 1
Kristian Vitozev
  • 5,791
  • 6
  • 36
  • 56