JavaScript / CSS应该放在HTML页面的底部吗?

时间:2022-11-20 11:05:36

I am using jQuery Mobile, and for now, I have the following at the bottom of my <head> tag:

我正在使用jQuery Mobile,现在,我在标签的底部有以下内容:

<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<title>help</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>

Since the user may have a very bad network access, I hope the user can load my page faster, even though the JavaScript or CSS is not ready.

由于用户可能有非常糟糕的网络访问,我希望用户可以更快地加载我的页面,即使JavaScript或CSS还没有准备好。

Will it work if I:

如果我:它会工作吗

  1. Put the <head> after <body>

    把放在之后

  2. Put the <script> in the end of <body>

2 个解决方案

#1


8  

  1. No you cannot put the head after the body.

    不,你不能把头放在身后。

  2. Yes you can, and that is the recommended way because then the browser loads the html components first like you are saying and applies your script afterwards. But you can place it just before you need it and no sooner really. Read more here.

    是的,你可以,这是推荐的方式,因为浏览器首先加载html组件,就像你说的那样,然后应用你的脚本。但是你可以在你需要它之​​前把它放在它之前。在这里阅读更多。

The css on the other hand should be linked inside your head tag.

另一方面,css应链接在head标签内。

#2


1  

You can't put <head> after <body>.

你不能把放在之后。

Putting the <script> in the end of <body> is good. but, the best solution for your problem is putting <script> in the <head> tag and use the async or defer attributes. Explanation can be found here.

And CSS should go to <head> always.

CSS总是应该去。

#1


8  

  1. No you cannot put the head after the body.

    不,你不能把头放在身后。

  2. Yes you can, and that is the recommended way because then the browser loads the html components first like you are saying and applies your script afterwards. But you can place it just before you need it and no sooner really. Read more here.

    是的,你可以,这是推荐的方式,因为浏览器首先加载html组件,就像你说的那样,然后应用你的脚本。但是你可以在你需要它之​​前把它放在它之前。在这里阅读更多。

The css on the other hand should be linked inside your head tag.

另一方面,css应链接在head标签内。

#2


1  

You can't put <head> after <body>.

你不能把放在之后。

Putting the <script> in the end of <body> is good. but, the best solution for your problem is putting <script> in the <head> tag and use the async or defer attributes. Explanation can be found here.

And CSS should go to <head> always.

CSS总是应该去。