0

我在 </html> 标记之前添加了我的 javascript 文件。但是我的一个脚本计算了我的网页的运行时间。所以我需要将我的一个脚本放在我的 HTML 页面的第一部分。脚本是这样的:

<script type="text/javascript">
    var NREUMQ=NREUMQ || [];
    NREUMQ.push(["mark","firstbyte",new Date().getTime()]);
</script>

将脚本放入的最佳行是什么?

1: <!DOCTYPE html>
2: <html xmlns="http://www.w3.org/1999/xhtml" lang="tr">
3:  <head>
4:      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
5:      <title>  example - example.com    </title>
6:       <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7:      <meta name="keywords" content="my words"/>
8:      <meta property="fb:page_id" content="12345" />
9:      
10:         <link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
11:       
12:         <script type="text/javascript" src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
13:       
14:         <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
15:         <link rel="icon" type="image/x-icon" href="/favicon.ico" />
16:         <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/apple-touch-icon-114-precomposed.png"/>
17:         
18:         <link rel="alternate" hreflang="tr" href="http://example.com/"/>
19:         <link rel="alternate" hreflang="en" href="http://example.com/eng"/>
20:         
21:         <link rel="stylesheet" type="text/css" href="/css/colorbox.css"/>
22:         <link rel="stylesheet" type="text/css" href="/css/demo_table.css"/>
23:     </head>
24: <body>
4

2 回答 2

1

第三行之后可以正常工作 - 假设脚本有第二部分来计算总时间?

Assuming you just want to see how fast your page loads, I strongly recommend grabbing Chrome and using the Network tab of the dev tools (press F12 to see the dev tools) to see how long components take to load. You might also want to install the Chrome PageSpeed plugin ( https://chrome.google.com/webstore/detail/pagespeed-insights-by-goo/gplegfbjlmmehdoakndmohflojccocli?hl=en ) which sits with the rest of the dev tools. It analyses the page and makes suggestions on how you could speed it up.

于 2013-08-29T08:42:58.640 回答
1

The best place to put the script is always within the head tag. <head></head>.

You can place your script in between line 3 and line 23.

于 2013-08-29T08:44:55.333 回答