3. 不要使用嵌入式CSS样式
当你在埋头写代码时,可能会经常顺手或偷懒的加上一点嵌入式css代码,就象这样
以下是引用片段:
<p style=“color: red;”>Oncoding编码营< SPAN>p>
|
更好的做法是,把这个P的样式定义在样式表文件里:
以下是引用片段:
- #someElement > p {
- color: red;
- }
|
4. 在页面head标签中引入所有的样式表文件
我们发现,在head标签中引入样式表,会加快网页加载速度,
以下是引用片段:
- <head>
- <title>My Favorites Kinds of Corn< SPAN>title>
- <link rel=“stylesheet” type=“text/css” media=“screen” href=“path/to/file.css” />
- <link rel=“stylesheet” type=“text/css” media=“screen” href=“path/to/anotherFile.css” />
- < SPAN>head>
|
5. 在页面底部引入JavaScript文件
要记住一个原则,就是让页面以最快的速度呈现在用户面前。当加载一个脚本时,页面会暂停加载,直到脚本完全载入。所以会浪费用户更多的时间。
如果你的JS文件只是要实现某些功能,(比如点击按钮事件),那就放心的在body底部引入它,这绝对是最佳的方法。
举例:
以下是引用片段:
- <p>And now you know my favorite kinds of corn. < SPAN>p>
- <script type=“text/javascript” src=“path/to/file.js”>< SPAN>script>
- <script type=“text/javascript” src=“path/to/anotherFile.js”>< SPAN>script>
- < SPAN>body>
- < SPAN>html>
|