<tfoot id='HIAR5'></tfoot>

<small id='HIAR5'></small><noframes id='HIAR5'>

<i id='HIAR5'><tr id='HIAR5'><dt id='HIAR5'><q id='HIAR5'><span id='HIAR5'><b id='HIAR5'><form id='HIAR5'><ins id='HIAR5'></ins><ul id='HIAR5'></ul><sub id='HIAR5'></sub></form><legend id='HIAR5'></legend><bdo id='HIAR5'><pre id='HIAR5'><center id='HIAR5'></center></pre></bdo></b><th id='HIAR5'></th></span></q></dt></tr></i><div id='HIAR5'><tfoot id='HIAR5'></tfoot><dl id='HIAR5'><fieldset id='HIAR5'></fieldset></dl></div>

        <bdo id='HIAR5'></bdo><ul id='HIAR5'></ul>
      <legend id='HIAR5'><style id='HIAR5'><dir id='HIAR5'><q id='HIAR5'></q></dir></style></legend>

        我什么时候应该使用内联和外部 Javascript?

        时间:2023-09-06

            • <bdo id='5ctpM'></bdo><ul id='5ctpM'></ul>
            • <legend id='5ctpM'><style id='5ctpM'><dir id='5ctpM'><q id='5ctpM'></q></dir></style></legend>

                  <tbody id='5ctpM'></tbody>

                1. <tfoot id='5ctpM'></tfoot>
                  <i id='5ctpM'><tr id='5ctpM'><dt id='5ctpM'><q id='5ctpM'><span id='5ctpM'><b id='5ctpM'><form id='5ctpM'><ins id='5ctpM'></ins><ul id='5ctpM'></ul><sub id='5ctpM'></sub></form><legend id='5ctpM'></legend><bdo id='5ctpM'><pre id='5ctpM'><center id='5ctpM'></center></pre></bdo></b><th id='5ctpM'></th></span></q></dt></tr></i><div id='5ctpM'><tfoot id='5ctpM'></tfoot><dl id='5ctpM'><fieldset id='5ctpM'></fieldset></dl></div>

                  <small id='5ctpM'></small><noframes id='5ctpM'>

                  本文介绍了我什么时候应该使用内联和外部 Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道在性能和易于维护方面,何时应该包含外部脚本或将它们与 html 代码内联编写.

                  I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.

                  对此的一般做法是什么?

                  What is the general practice for this?

                  真实世界场景 - 我有几个需要客户端表单验证的 html 页面.为此,我使用了一个包含在所有这些页面上的 jQuery 插件.但问题是,我是否:

                  Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I include on all these pages. But the question is, do I:

                  • 编写内联配置此脚本的代码?
                  • 在一个文件中包含所有这些 html 页面共享的所有位?
                  • 将每个位包含在单独的外部文件中,每个 html 页面一个?

                  谢谢.

                  推荐答案

                  在最初发布此答案时(2008 年),规则很简单:所有脚本都应该是外部的.兼顾维护和性能.

                  At the time this answer was originally posted (2008), the rule was simple: All script should be external. Both for maintenance and performance.

                  (为什么是性能?因为如果代码是分开的,它更容易被浏览器缓存.)

                  (Why performance? Because if the code is separate, it can easier be cached by browsers.)

                  JavaScript 不属于 HTML 代码,如果它包含特殊字符(如 <>)甚至会产生问题.

                  JavaScript doesn't belong in the HTML code and if it contains special characters (such as <, >) it even creates problems.

                  如今,网络可扩展性已经发生了变化.由于发出多个 HTTP 请求的延迟,减少请求的数量已成为一个有效的考虑因素.这使得答案更加复杂:在大多数情况下,仍然推荐使用外部 JavaScript.但在某些情况下,尤其是非常小的代码段,将它们内联到网站的 HTML 中是有意义的.

                  Nowadays, web scalability has changed. Reducing the number of requests has become a valid consideration due to the latency of making multiple HTTP requests. This makes the answer more complex: in most cases, having JavaScript external is still recommended. But for certain cases, especially very small pieces of code, inlining them into the site’s HTML makes sense.

                  这篇关于我什么时候应该使用内联和外部 Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:合并/展平数组数组 下一篇:使用地图时反应'无法读取未定义的属性'

                  相关文章

                    <bdo id='6oYaw'></bdo><ul id='6oYaw'></ul>
                  1. <i id='6oYaw'><tr id='6oYaw'><dt id='6oYaw'><q id='6oYaw'><span id='6oYaw'><b id='6oYaw'><form id='6oYaw'><ins id='6oYaw'></ins><ul id='6oYaw'></ul><sub id='6oYaw'></sub></form><legend id='6oYaw'></legend><bdo id='6oYaw'><pre id='6oYaw'><center id='6oYaw'></center></pre></bdo></b><th id='6oYaw'></th></span></q></dt></tr></i><div id='6oYaw'><tfoot id='6oYaw'></tfoot><dl id='6oYaw'><fieldset id='6oYaw'></fieldset></dl></div>

                    <legend id='6oYaw'><style id='6oYaw'><dir id='6oYaw'><q id='6oYaw'></q></dir></style></legend>

                    <small id='6oYaw'></small><noframes id='6oYaw'>

                    <tfoot id='6oYaw'></tfoot>