TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

LoadJS – A tiny async loader for modern browsers (710 bytes)

91 点作者 andres超过 8 年前

9 条评论

pygy_超过 8 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;walmartlabs&#x2F;little-loader" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;walmartlabs&#x2F;little-loader</a> is smaller (519 bytes min+gzipped), supports IE8, and fires either on script load or on error synchronoulsy (so that globals won&#x27;t be overwritten by code that runs between script loading and the callback firing). The thing is tested on SauceLabs down to IE8.<p>The drawback is a lower level API, and it is JS only. AFAIK loading CSS consistently cross browser is also a mine field if you want consistent error handling.<p><pre><code> window._lload(&quot;http:&#x2F;&#x2F;example.com&#x2F;foo.js&quot;, function (err) { &#x2F;&#x2F; `err` is script load error. &#x2F;&#x2F; otherwise, foo.js is loaded! }&#x2F;*, [optional context (`this`) variable here] *&#x2F;);</code></pre>
评论 #13175750 未加载
franciscop超过 8 年前
This looks like the perfect case for using Promises...<p><pre><code> loadjs(&#x27;foobar&#x27;).then(() =&gt; { &#x2F;&#x2F; foobar.js loaded }); </code></pre> And then with the newer spec:<p><pre><code> await loadjs(&#x27;foobar&#x27;); &#x2F;&#x2F; foobar.js loaded </code></pre> Such a pity that instead it uses a proprietary format.<p>Edit: you could still add all other nice things without compromising the main thing, for example to add a &quot;before&quot;:<p><pre><code> loadjs.before(fnA).before(fnB).load(&#x27;foobar&#x27;).then(() =&gt; {});</code></pre>
评论 #13174762 未加载
评论 #13175457 未加载
评论 #13174592 未加载
评论 #13174714 未加载
评论 #13174545 未加载
gliptic超过 8 年前
I made a similar thing that is supposed to be vaguely require.js compatible in 541-588 bytes, depending on enabled features [1]. Not production ready :).<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;gliptic&#x2F;hypjs&#x2F;blob&#x2F;master&#x2F;src&#x2F;amd.ts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gliptic&#x2F;hypjs&#x2F;blob&#x2F;master&#x2F;src&#x2F;amd.ts</a>
alz超过 8 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;QubitProducts&#x2F;micro-amd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;QubitProducts&#x2F;micro-amd</a> is another project with similar goals. Its pretty small, amd compliant and battle tested
tannerwj超过 8 年前
Seems handy for the callbacks, but will this be as useful once http2 is the default?
评论 #13174777 未加载
lloydjatkinson超过 8 年前
back in the day you just did script src... none of this bullshit
评论 #13177014 未加载
manishsharan超过 8 年前
Wow. This makes Labjs, which has been my preferred loader, seem heavy.
Exuma超过 8 年前
That&#x27;s cool. Would this help with my page speed score that almost is always like a D- for stuff related to async&#x2F;css&#x2F;js and &#x27;deferred&#x27; loading?
评论 #13175303 未加载
jarnix超过 8 年前
It seems to lack the handling of timeouts, which is necessary in these async days.