在HTML文件中应该放置Jquery和Bootstrap? [英] Where in the HTML file should Jquery and Bootstrap be placed?

查看:49
本文介绍了在HTML文件中应该放置Jquery和Bootstrap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好奇我放置Jquery和Bootstrap文件的位置。他们建议您始终将底部放在底部以达到性能目的,但当我检查使用Jquery / Bootstrap的网站时,大多数用户总是将它们放在顶部。我还应该在bootstrap / Jquery文件之前或之后加载我自己的JavaScript文件吗?

Curious at to where I place my Jquery and Bootstrap files. They recommend that you always place at the bottom for performance purposes yet when I check sites that use Jquery/Bootstrap the majority of users always place them at the top. Also should I be loading my own JavaScript files before or after the bootstrap/Jquery files?

我认为我在引导程序文件之前首先加载了我自己的css文件我想覆盖它们的一些样式,这是正确的并且同样适用于javascript文件吗?

I take it that I load the my own css file first before the bootstrap file if I want to override some of their styling, is this correct and does the same apply to javascript files?

推荐答案

通常样式表中的样式表收盘前的头部和脚本< / body> 标签:

Typically stylesheets in the head and scripts before the closing </body> tag:

<html>
  <head>
    <link rel="stylesheet" href="bootstrap.css">
    <link rel="stylesheet" href="your-other-styles.css">
  </head>
  <body>
    <!-- content -->
    <script src="jquery.js"></script>
    <script src="bootstrap.js"></script>
    <script src="your-other-scripts.js"></script>
  </body>
</html>

您需要将来自jQuery和Bootstrap等供应商的文件包含在之前你的。这意味着:

You'll want files from vendors such as jQuery and Bootstrap to be included before yours. This means that:


  • CSS:您可以使用自己的*

  • 脚本覆盖其样式:您可以访问添加到全局范围的任何对象,例如 window (jQuery添加 $
    for示例)

  • CSS: You can override their styles with your own*
  • Scripts: You have access to any objects added to the global scope such as window (jQuery adds $, for example)

但是,如果您需要在加载内容之前使用脚本(例如Modernizr),那么将其放入< head> 确保它在您的任何内容之前就绪。

However, if you require a script to be available before your content loads (such as Modernizr), then putting it in the <head> ensures it's ready before any of your content.

在底部包含脚本可确保实际首先加载页面内容;当最终下载脚本时,内容(DOM)将为您的脚本操作做好准备。

Including scripts at the bottom ensures that the actual page content is loaded first; when the scripts are finally downloaded the content (DOM) will be ready for your scripts to manipulate.


*假设您的选择器特性至少是等于供应商CSS中的那些

* assuming your selector specificity is at least equal to those in your vendor CSS

这篇关于在HTML文件中应该放置Jquery和Bootstrap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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