在网页中添加社交媒体资源时,传统方法会导致从其他域加载大量外部 JS,仅加载带有品牌图像背景的 iframe 或锚点。以下可能是网络上传输最多的文件(在http://www.google-analytics.com/ga.js 36.35KB 之后,这对许多人来说是不可避免的)
http://connect.facebook.net/en_US/all.js 181.30KB(59.06KB 压缩)
https://platform.twitter.com/widgets.js 75.19KB(24.42KB 压缩)
https://apis.google。 com/js/plusone.js 16.71KB
http://assets.pinterest.com/js/pinit.js(这个很小,但仍然不需要连接)
例如,http ://connect.facebook.net/en_US/all.js 只做一件事:添加 iFrame
<iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Flavishdream&width=292&height=180&colorscheme=light&show_faces=true&border_color&stream=false&header=false" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:292px; height:180px;" allowtransparency="true"></iframe>
Twitter 和 Google Plus 脚本执行非常相似的任务,只是将小的 HTML 块添加到页面中。
为什么不只编写那些 iFrame、图像和锚点 HTML 呢?