简体   繁体   English

加载样式表和JavaScript花费的时间太长

[英]Loading stylesheets and JavaScript taking too long

What should I do to decrease load time? 我该如何减少加载时间?

<head>
    <title>NCI SwitchGears</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="bootstrap-3.3.4-dist/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="menu/styles.css">
    <script src="bootstrap-3.3.4-dist/js/jquery-latest.min.js" type="text/javascript"></script>
    <script src="menu/script.js"></script>
</head>

Google provides a nice tool to help you speed up the loading times of your pages https://developers.google.com/speed/pagespeed/insights/ Google提供了一个很好的工具来帮助您加快页面的加载时间https://developers.google.com/speed/pagespeed/insights/

Another nice online tool can be found here 另一个不错的在线工具可以在这里找到

As a general rule: 作为基本规则:
- load 1 js files and 1 css file - compressed -加载1个js文件和1个CSS文件-压缩
- have your js at the bottom of the page, not in header -将js放在页面底部,而不是标题中
- load social tools/scripts via ajax, after page has load -页面加载后通过Ajax加载社交工具/脚本
- optimize the images/graphics you use on your template -优化您在模板上使用的图像/图形
- set proper expiration headers and caching options -设置适当的到期标头和缓存选项

More specific instructions for your pages you can find in the above tools. 您可以在上述工具中找到针对您页面的更具体说明。

  1. You're loading jQuery twice. 您要加载jQuery两次。 Once locally, and once remotely. 一次在本地,一次在远程。
  2. Consider using Require.JS to load your JS on demand 考虑使用Require.JS按需加载JS
  3. Combine Style sheets to one request. 将样式表组合到一个请求。 Make sure you are using modular styles and again, load on demand. 确保使用模块化样式,然后再次按需加载。
  4. JS move to footer where appropriate JS在适当的地方移至页脚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM