Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help me to understand <script src="some.js?param1=one;param2=two" />

I observed chunks like below sometimes on web pages. So i am curious to know what this really does? or why its written in such a way?

<script src="somefile.js?param1=one&param2=two" />

i can only make out following few intentions behind it

  • Its not page URL (i mean .aspx/.php/.jsp etc.) so its not hacking kind of code where user can add code like this to pass data without getting users attention as its tag which does not render on UI OR implementing old type of AJAX alternative
  • This kind of URL param are useful if user do not wish the JS file (any other resource like image) to get cached. This can be quick way to manage caching

But i am unable to figure out following

  • Looks like page URL parameters but are these parameters anyway readable in JavaScript file and have some additional utility?
  • Do these parameters have any extra role to play here ?
  • What are the other possible practical scenarios where code like this can be/is used?

So please provide some inputs related with the same

Thanks,

like image 590
Anil Namde Avatar asked Dec 23 '09 17:12

Anil Namde


2 Answers

Running Non-JS Code within .js Extensions

In cases like this, that source .js file might (given proper server-configurations) actually have PHP/.NET code within it, which can read those appended values.

As you said, Avoiding Cache...

Additionally, people will at times append a random string at the end of their referenced elements to avoid loading cached data.

like image 152
Sampson Avatar answered Sep 21 '22 03:09

Sampson


The URL having '.js' means nothing. It could still be handled by a server-side script like an ASP or PHP.

like image 29
Nicolás Avatar answered Sep 20 '22 03:09

Nicolás