- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
用ControlJS优化阿里妈妈广告
长时间以来阿里妈妈的广告载入策略一直存在些问题,很多页面也因为阻塞式的广告载入而被拉低性能,影响用户体验。毕竟阿里妈妈广告的渲染依赖于诸多嵌套的document.write。ControlJS的目标就是解决js的阻塞式渲染,因此灵玉急不可耐想与同仁们共同去揭秘ControlJS……
Steve Souders在2010年12月份发布了ControlJS项目,该项目是让开发者更好的去控制javascript文件的下载和执行,从而提高了页面脚本的加载速度。
Steve提出了一个非常具有创造性的思想,就是预先异步下载javascript文件而不解析执行,直到需要的javascript处理时才去真正的执行。这一点得到了很多人的关注与验证。Nicholas Zaka也因ControlJS引发了很多思考,并分析了ControlJS和LABjs 的区别所在,详细内容可以阅读Thoughts on script loaders和Separating JavaScript download and execution。Steve使用3篇博闻详细介绍了ControlJS:异步加载、延迟执行、重写document.write。
ControlJS的原理
异步加载
ControlJS本身是异步进行加载的,首先将script的标签type属性值更改为浏览器无法识别的类型,这样浏览器不会认为这是一个脚本。本身异步加载的ControlJS执行时开始遍历type=”text/cjs”的script标签(包括内嵌脚本),如果存在”DATA-CJSSRC”属性将创建IMAGE或者OBJECT对象(依赖浏览器而选择),去异步预下载脚本文件并缓存文件,直到window.onload时解析并执行javascript,同时第二次去遍历遗漏的script标签。
具体操作可看 Async WITH ControlJS
This page contains 3 scripts in the HEAD:
an external script (main.js) that takes 4 seconds to download
an inline script
another external script (page.js) that takes 2 seconds to download
This page uses ControlJS to improve page performance. And indeed this page feels faster than the async baseline example. Comparing the HTTP waterfall charts shows that this page loads one second faster (~4 seconds versus ~5 seconds). More importantly, the page feels faster because it starts rendering immediately. Comparing the HTTP waterfall chart to the one from the baseline example we see that with ControlJS rendering (indicated by the vertical green line) starts much sooner in the page load timeline.
Another difference between the two waterfall charts is that this page has 3 more resource requests than the baseline example. One of these additional requests is control.js itself. This is loaded asynchronously so it has little impact on page performance. The other two requests are repeated requests for main.js and page.js when they are inserted into the page as SCRIPT elements dynamically. These requests are read from cache (note the thin blue bar in the waterfall chart)
文档评论(0)