HTML页面顶部的脚本标记

时间:2013-08-29 08:41:54

标签: javascript html html5 performance-testing

我在<之前添加我的javascript文件/ html>标签。但我的一个脚本计算了我的网页的运行时间。所以我需要将我的一个脚本放在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>

2 个答案:

答案 0 :(得分:1)

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

假设您只想查看网页的加载速度,我强烈建议您抓住Chrome并使用开发工具的Network标签(按F12查看开发工具)以查看组件加载的时间。您可能还想安装与其他开发工具一起使用的Chrome PageSpeed插件(https://chrome.google.com/webstore/detail/pagespeed-insights-by-goo/gplegfbjlmmehdoakndmohflojccocli?hl=en)。它分析页面并就如何加快速度提出建议。

答案 1 :(得分:1)

放置脚本的最佳位置始终在head标记内。 <head></head>

您可以将脚本放在第3行和第23行之间。