-2

To avoid cache, i included my css and js files through script tag.It generates a random number which will be added as query string to the files.

 <script>document.write('<link rel="stylesheet" href="css/style.css?dev=' + Math.floor(Math.random() * 100) + '"/>');</script>

But most of times, when i hit the url, instead the html page, the css file is getting print directly in the browser

is the content header is causing the issue, should i need to add "type" parameter for css> Please provide me a soultion

user1153484
  • 197
  • 3
  • 13

2 Answers2

2

There are better ways to stop caching. What if JS is disabled?

<script>document.write('<link rel="stylesheet" href="css/style.css?dev=' + Math.floor(Math.random() * 100) + '"\>');</script>
pee2pee
  • 3,619
  • 7
  • 52
  • 133
2

If youre looking to speed things up in regards to your css and js files have you looked into script bundling and minification. That will speed your page up and remove clutter from your markup. Also, its mostly almost exclusively going to be Also look HERE.

 <link rel="stylesheet" type="text/css" href="theme.css">
Community
  • 1
  • 1
Leonardo Wildt
  • 2,529
  • 5
  • 27
  • 56