What’s the use of that line?

Asked

Viewed 90 times

0

I intend to know what this line of code within my HTML does? Why when I delete it the site stops working?

<script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
  • 1

    This line imports a script by passing a parameter nocache whose value is defined by md5(microtime()) from php.

  • 4

    That means the model you picked up is full of tricks. First, if the site for whole, is pq depends all on a JS (if it is a game, or very specific application, it is even understandable. If it is a conventional site, it should not depend entirely on JS). Second, that the site will always reload the JS every time, because the url changes all the time, which is bad for band and performance. Third that the person does not know well PHP, pq o uniqid is much more suitable for this and does not run the risk of collision. Fourth, if it is only to have no cache, do not need to write nocache=, would suffice main.js?<?php....

  • Did the answer solve your problem? Do you think you can accept it now? See [tour] to understand how it works. It would be helpful to indicate to everyone that the solution was useful and satisfactory for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

It is unlikely that the nocache is necessary at some point in this script, but only seeing what is inside him to say what. Apparently it was put (as its name already says) to the browser not cache the script, because the URL will change every time the page is reloaded, and what goes for the browser is the whole, not just the main.js.

Anyway the reason the site stopped working is that it adopted a dependency pattern of this script. The ideal is that this does not happen, IE, the site may not even be in its best state but should work anyway. Exists technique for this. It is understandable that the site requires the presence of JS and scripts specific to work well, but completely prevent use is not usually a good idea.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.