0

I have seen code like this:

<script type="text/javascript" src="js/my_js.js?id=<?php echo time(); ?>"></script>

I do not understand the reason for the id, nor how to use the id in the .js file, if this is possible.

Thanks.

1
  • Looks like a timestamped javascript source code to make sure it is downloaded every time the html page is loaded into the browser. Commented Jan 15, 2013 at 23:14

1 Answer 1

4

It is to force the browser to refresh the JavaScript file, otherwise the browser may display a cached version at a later date.

You can also do this to CSS files.

Sign up to request clarification or add additional context in comments.

2 Comments

Can I pass some values to the javascript in this way, or it is only to refresh?
Not really. I say this because, technically sure you could do it since your JavaScript has access to the DOM and maybe search it via regex but there is much much much better ways of doing so. A better way to pass a variable would be to include it in a hidden fields value, or as an actual javascript variable in the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.