Where to insert JS and CSS files into HTML?

Asked

Viewed 1,838 times

-3

Thinking of performance, in which part of HTML should I insert CSS and JS files. I know which JS files should be inserted before closing the tag </body> not to block charging and if possible in a assíncrona , but what about CSS?

1 answer

-1


In my opinion the best practice is to put the CSS inside the tag head:

<head>
  <link rel="stylesheet" href="css/layout.css" type="text/css">
</head>

And the Javascript files before closing the tag body:

  <script type="text/javascript" src="script.js"></script>
</body>

Translated from: Where to put CSS and Javascript

  • It’s a very old answer and I don’t think it covers current scenarios.

  • 8

    If you know that because you asked the question?

  • I thought that hj were using other techniques, so I replied that "I believe", but LINQ commented on a response that helped me understand the context.

  • 1

    @Matheus This will depend a lot on your code. By default, is what friend Perozzo put there in his answer. Sometimes you may want to call a CSS or script anywhere on the page.

Browser other questions tagged

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