移动网站要使用什么(amd)脚本加载器 [英] what (amd) script loader to use for mobile site

查看:102
本文介绍了移动网站要使用什么(amd)脚本加载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始在新版本的移动网站上工作.我正在研究使用AMD脚本加载器,并将其范围缩小到require和lsjs.我知道这两者都有很多优点和缺点,但是我正在尝试为我的网站的移动版本找到所有这些优点和缺点.有没有人在移动平台上使用过这个库?只是想在这里讨论人们认为最好的方法是什么. (具有1500个代表的任何人都想创建一个lsjs标记:)).这些库的创建者(托德·伯克或理查德·巴克豪斯)也许对此都有意见

I'm starting work on a new version of a mobile site. I am looking into using an amd script loader and have pretty much narrowed it down to require and lsjs. I know there are many pro's and con's to both, but I am trying to figure all of those out for the mobile version of my site. Does anyone have experience with this lib's at the mobile level? Just trying to get a discussion going here of what people think the best way to go is. (anyone with a 1500 rep want to create an lsjs tag :) ). Maybe either of the creators of these libraries (todd burke or richard backhouse) have an opinion on this

谢谢

感谢西蒙·史密斯(Simon Smith)在下面提供的详细信息.有人使用过lsjs吗?就速度而言,它看起来很有希望,但没有用户基础,文档或require/curl的功能(但我认为),但看起来还是很有希望的

thanks to Simon Smith for the great info down below. has anyone used lsjs? it looks very promising in terms of speed, but does not have the user base, documentation, or (i think) features of require/curl, but still looks very promising

推荐答案

在您准备好投入生产之前,我会说使用RequireJS.然后编译您的脚本,并用Almond替换RequireJS.这是James Burke(RequireJS的作者)制作的一个准系统库,因此您可以依靠它无缝地工作:

I would say use RequireJS until you're ready to go to production. Then compile your scripts and replace RequireJS with Almond. It's a bare-bones library made by James Burke (author of RequireJS) so you can rely on it to work seamlessly:

一些开发人员喜欢使用AMD API编码模块化JavaScript, 但是在进行优化的构建后,他们不想包含完整的 像RequireJS这样的AMD加载器,因为它们不需要所有这些 功能.某些使用案例(例如移动设备)对文件非常敏感 大小.

Some developers like to use the AMD API to code modular JavaScript, but after doing an optimized build, they do not want to include a full AMD loader like RequireJS, since they do not need all that functionality. Some use cases, like mobile, are very sensitive to file sizes.

通过在构建文件中包含杏仁,无需RequireJS. 使用Closure Compiler和 压缩.

By including almond in the built file, there is no need for RequireJS. almond is around 1 kilobyte when minified with Closure Compiler and gzipped.

https://github.com/jrburke/almond

Curl.js也是一个选项.我没有使用过它,但是知道它比RequireJS小得多.对原因做了一些研究:

Curl.js is also an option. I haven't used it but know that is a lot smaller than RequireJS. Did a bit of research as to why:

RequireJS通过Curl(通过James Burke)执行以下操作:

RequireJS does the following over Curl (via James Burke):

  • 支持multiversion/context,对模拟测试很有用,但是如果没有它,您可以轻松实现
  • 支持通过require加载普通的JS文件,而不必是AMD模块
  • 支持特殊检测并与jQuery的较早版本一起使用(如果使用jQuery 1.7.1或更高版本,应该不会有问题)
  • (目前)更好地支持简化包装的commonjs样式:define(function(require){});
  • Supports multiversion/contexts, useful for mock testing, but you can get by without it
  • Supports loading plain JS files via require, does not have to be an AMD module
  • Supports special detection and work with older versions of jQuery (should not be an issue if you use jQuery 1.7.1 or later)
  • (At the moment) better support for simplified wrapped commonjs style: define(function(require) {});

简而言之,如果您只打算在应用程序中处理AMD模块, 不需要多版本/上下文支持,并且不使用 简化的commonjs包装样式,或使用较旧的jQuery,然后 卷曲可能是个不错的选择.

In short, if you are only going to deal with AMD modules in your app, do not need the multiversion/context support, and are not using the simplified commonjs wrapping style, or using an older jQuery, then curl can be a good choice.

https://groups.google.com/forum/? fromgroups =#!topic/requirejs/niUyLZrivgs

还有Curl的作者:

RequireJS在curl.js之外的更多地方运行,包括WebWorkers和 node.js.与curl.js相比,它还有更多的战斗测试",这可能 意味着它在边缘情况下的错误更少. curl.js也缺少一些 重要功能,例如预加载隐式依赖项和 支持AMD包装的commonjs模块.这些都进来了 版本0.6(下周晚).

RequireJS runs in more places than curl.js, including WebWorkers and node.js. It's also got more "battle testing" than curl.js, which may mean it has less bugs around edge cases. curl.js is also missing a few important features, such as preloading of implicit dependencies and support for AMD-wrapped commonjs modules. These are both coming in version 0.6 (late next week).

从好的方面来说,curl.js ...

On the plus side, curl.js...

的大小仅为RequireJS的1/4,即使与 js!和domReady!插件的大小仍不到一半.

is as small as 1/4 the size of RequireJS -- even when bundled with the js! and domReady! plugins it is still less than half the size.

在加载模块时比RequireJS快,但仅在有意义的情况下如此 IE6-8或处于开发(非构建)环境中.

is faster at loading modules than RequireJS, but only meaningfully so in IE6-8 or in development (non-build) environments.

支持可插拔 除AMD以外的其他格式的模块加载程序(我们正在开发未包装的 例如CJSM/1.1和CJSM/2.0).

supports pluggable module loaders for formats other than AMD (we're working on unwrapped CJSM/1.1 and CJSM/2.0, for instance).

支持基于配置 通过诸如wire.js(通过cram.js)之类的IOC容器进行依赖管理.

supports configuration-based dependency management via IOC containers like wire.js (via cram.js).

支持css的内联(通过cram.js)和css的串联(通过) cram.js 0.3年底)

supports inlining of css (via cram.js) and concatenation of css (via cram.js 0.3 by end of year)

https://github.com/cujojs/curl/issues/35# issuecomment-2954344

这篇关于移动网站要使用什么(amd)脚本加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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