加载外部CSS和JavaScript文件的顺序 [英] Order of loading external CSS and JavaScript files

查看:113
本文介绍了加载外部CSS和JavaScript文件的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有第三方应用程序加载许多 css和javascript文件,我现在想通过将所有javascripts合并到一个文件来优化它,由yuicompressor压缩,但是...我们有这样的组合:

I have a third party application that loads many css and javascript files, and I now want to optimize this by concatinating all the javascripts into one file, compressed by the yuicompressor, but ... when we have a mix like:

<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
<link rel="stylesheet" href="style1.css" type="text/css" />
<script type="text/javascript" src="script3.js"></script>
<script type="text/javascript" src="script4.js"></script>

这里有中间的css是否重要?我应该整理和yuic压缩4个javascripts并在CSS之前或之后加载吗?

Does it matter that there's a css in the middle here? Should I concatinate and yuicompress the 4 javascripts and load them before the CSS or after?

推荐答案

查看雅虎加速网站的最佳实践,他们建议先加载你的css(最好是在标题中),然后你的js last(在身体中的所有内容之后)。 Google的最佳做法也建议首先加载CSS。

Check out Yahoo's Best Practices for Speeding Up Your Web Site, they recommend loading your css first (preferably in the header), and your js last (after all the content in the body). Google's best practices also recommended loading CSS first.

这篇关于加载外部CSS和JavaScript文件的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆