这是初始化快速点击的好方法吗?

Is this a good method to initialise fast click?

我试图保持我的 html 干净,因此通过我的 app.js 文件需要库/插件,所有 javascript / jquery 逻辑都发生在该文件中。我正在使用 FastClick 库来省略 300 毫秒的点击延迟并以这种方式对其进行初始化。

jQuery(document).ready(function ($) {
    'use strict';

    /* Load and initialize FastClick, ommits 300ms tap delay */
    $.getScript('lib/fastclick.js', function () {
        new FastClick(document.body);
    }); /* END FastClick */

}); /* END jQuery */

这是否具有语义意义?使用它而不是在 html 页面中添加 fastclick.js 文件会不会更有害?

它具有语义意义,并​​且从 fastclick docs 来看,它看起来并不有害。

Include fastclick.js in your JavaScript bundle or add it to your HTML page...

他们说将其作为串联文件或独立文件包含是安全的。您可以随意包含 FastClick 源代码,但您认为合适。

实际上,他们的文档使 FastClick 的初始化变得过于复杂。 document.documentElement 属性 在 JavaScript 开始执行时可用,代表 <html> 元素。这可以用作 FastClick 的根元素,不需要 DOMContentLoaded 或 domready 事件处理程序:

new FastClick(document.documentElement);

不需要事件处理程序。现在,如果需要,您可以在页面加载时响应点击,并且在完整 HTML 文档被解析之前。

编辑:@jungy 在他的评论中提出了一个很好的观点:

... you are waiting till the DOM is ready before downloading the library.

完整代码示例:

jQuery.getScript("lib/fastclick.js", function() {
    new FastClick(document.documentElement);
});