理想情况下,我正在寻找一个 Javascript 资源加载器,它将:
(1) 允许我进行“就绪”调用,例如head.js 确实如此,例如
head.ready(function() {
$("#my").jquery_plugin();
});
// load jQuery whenever you wish bottom of the page
head.js("/path/to/jquery.js");
(2) 加载 CSS 文件,例如 yepnope(也可以使用 css! 前缀处理末尾带有哈希的文件名)。我并不特别需要条件加载功能(在现阶段)。
(3) 理想情况下,即使进行多次调用,也仅加载资源一次(head.js 自动执行此操作,yepnope 使用过滤器执行此操作)。
目前,我正在同时使用 head.js 和 yepnope,因为我无法找到同时支持前两个要求的工具。显然这并不理想,因为两者(带有过滤器和前缀)一起缩小到 7kb。我认为这作为引导脚本有点太重了。
一种选择是使用两者的组合来推出我自己的功能,并删除我不需要的功能......但我宁愿坚持使用将受到支持的功能,以减少未来更新等的痛苦。
Ideally I'm looking for a Javascript resource loader that will:
(1) Allow me to make "ready" calls like head.js does, e.g.
head.ready(function() {
$("#my").jquery_plugin();
});
// load jQuery whenever you wish bottom of the page
head.js("/path/to/jquery.js");
(2) Load CSS files like yepnope (which can also handle file names with hash on the end by using the css! prefix). I don't particularly need the conditional load functionality (at this stage).
(3) Ideally, only load resources once even if multiple calls are made (head.js does this automatically, yepnope does this with a filter).
At the moment I'm resorting to using both head.js and yepnope, as I haven't been able to find one that supports both the first two requirements. Obviously this is not ideal, as both together (with filters and prefixes) come to 7kb minified. I think this is a bit too heavy as a bootstrap script.
One option is roll my own using a combination of the two and strip out the functionality I don't need... but I'd rather stick to one that's going to be supported to reduce the pain of future updates etc.
发布评论
评论(1)
所以我们坚持使用 head.js 和 yepnope 的组合,直到出现更好的东西。
So we stuck with a combination head.js and yepnope until something better comes out.