将常用的小jQuery插件附加到common.js文件的末尾是否被视为不良做法或不道德? [英] Is it considered bad practice or unethical to append always used small jQuery plugins to the end of a common.js file?

查看:88
本文介绍了将常用的小jQuery插件附加到common.js文件的末尾是否被视为不良做法或不道德?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的很多jQuery项目都使用子菜单。我坚信使用 hoverIntent 插件而不是jQuery的原生 hover() ,出于可用性原因(并防止事故被触发)由用户)。

A lot of my jQuery projects use sub menus. I'm a firm believer of using the hoverIntent plugin over jQuery's native hover(), for usability reasons (and to prevent events being fired by accident by the user).

因为这个插件在我的网站的每个页面上使用,并且因为它只有8行缩小,所以我只是将它附加到我的末尾 common.js 文件,包含在每个页面上。我保留了作者评论的完整性。

Because this plugin is used on every page of my site, and because it is only 8 lines minified, I just appended it to the end of my common.js file, which is included on every page. I kept the author comments intact.

这样做的好处是减少一个HTTP请求。每个页面也很常见,因此不需要单独进行缓存控制。

The advantage of this is one less HTTP request, for one. It is also common to every page, so it doesn't need to be cache controlled separately.

,这是一个好习惯吗?我是否对原始开发人员不道德,最后将代码集中在一起

But, is this good practice? Am I being unethical to the original developer, by lumping his code right at the end?

所有第三方插件是否都应该存在于他们自己的JS中文件,我应该把它们放在一起自动缩小/连接过程吗?

Should all third party plugins live in their own JS file, and should I leave something like lumping it all together to an automatic minifiying/concatenating process?

谢谢。

推荐答案

只要你保持许可证的完整性(如果可能的话,在哪里找到插件),这没有任何问题...任何插件作者都应该

As long as you're keeping the license intact (with where to find the plugin if possible), there's nothing wrong with this...any plugin author should be ok with this in my opinion since this is a purely technical decision.

通过组合,您可以大大减少用户的HTTP流量,从而产生更好的用户体验...这里的好处非常明确,如果包含以下内容,我认为您的安全和道德:

By combining, you're greatly reducing the HTTP traffic for the user, resulting in a better user experience...the benefits are pretty clear-cut here, and if the following are included, I think you're safe and ethical:


  1. 许可证完整且完整(与原始插件中一样)

  2. 您遵守该许可证

  3. 插件来自何处,如果它不在原始IMO中,请添加它。

如果有帮助,我个人确切地做了什么你问的是,所有杂项插件都在我的项目中的一个 jquery.plugins.misc.js 文件中,其余部分缩小了,较大的插件本身就是..但是他们最终都在一个由闭包编译器压缩的大文件中,许可证完好无损,如果可能的话,还有找到插件的地址的URL。

If it helps, I personally do exactly what you're asking about, all miscellaneous plugins are in one jquery.plugins.misc.js file in my project that gets minified with the rest, larger plugins are by themselves...but they both end up in one larger file compressed by the closure compiler with the licenses intact, and if at all possible, URLs of where to find the plugins.

这篇关于将常用的小jQuery插件附加到common.js文件的末尾是否被视为不良做法或不道德?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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