1

I have a script tag and css tag like this:

<script type='text/javascript', src='version.js'></script>
<script src="js-new/main.js?version="+version></script>
<link rel="stylesheet" type="text/css" href="main.css?version="+version>

version.js

var version = 1;
return version;

I know I am doing it wrong but is there a way to do it just using javascript.

PS: I think I was not very clear. I just want to update version, not append the full script tag as it will already be there.

Sumit Sahay
  • 504
  • 4
  • 22
  • More duplicates: http://stackoverflow.com/questions/9413737/how-to-append-script-script-in-javascript http://stackoverflow.com/questions/610995/cant-append-script-element – mplungjan Aug 16 '16 at 08:48
  • @mplungjan I want to add version and keep on updating it on all the files. The duplicate links are not what I am looking for. – Sumit Sahay Aug 16 '16 at 08:50
  • @mplungjan can you please remove the "marked duplicate" – Sumit Sahay Aug 16 '16 at 08:57
  • With a simple change it will work: remove the "return version" and the comma from the script tag and have `` – mplungjan Aug 16 '16 at 09:06
  • 1
    Alternatively set the version on the server. You cannot read the version inside a stylesheet – mplungjan Aug 16 '16 at 09:10
  • but there are not just two files, there are many more plus, there different html pages with different tags. More convenient option will be adding version to all the files so suppose next day any one includes a new file, the version will automatically be added to it. – Sumit Sahay Aug 16 '16 at 09:11
  • yes, server will be good but for static files which are written in html and not jade (cannot use grunt, gulp there). Is there an option? – Sumit Sahay Aug 16 '16 at 09:12
  • The script I suggested will work for all files you wish to include. Unless you document.write the files, that is the way to go. Using createElement is the preferred way and if you had to change your page to use document.write you should use createElement instead. There are no other ways to have dynamic source in a page than the two I suggested, server or client side. – mplungjan Aug 16 '16 at 09:14

0 Answers0