手动加载 <iframe>

默认不载入面积较大的 <iframe> 元素,减免一部分不必要的资源消耗。不是 lazyload;点击按钮(而不是点击 <iframe> 的任意位置)才会加载,以免误触。

作者
Crystal-RainSlide
日安装量
0
总安装量
256
评分
1 0 0
版本
1.3
创建于
2020-10-05
更新于
2020-12-09
许可证
暂无
适用于
所有网站

It's main purpose is to reduce some unnecessary resource consumption caused by <iframe>s, not block every <iframe>-based share buttons (add some social-blocking rulesets into your AdBlocker to block the share buttons) or visualize the existence of every <iframe>s. So expect it to ignore lots of <iframe>s but only seems to suspend the embed YouTube videos.

will ignore <iframe>s that:

  • has srcdoc attribute
  • doesn't have src attribute
  • the value of its src attribute is not a valid URL
  • the URL of its src attribute:
    • has a origin that is "null", and/or
    • has a protocol that is not "https:" or "http:"
    • (in other words, is "about:blank", "javascript:*" or "data:*")
  • narrower than 72px, or generally smaller than 128x128px

Just modify the code to change the behavior. If you need a lazyload version, but can't code it yourself, I'm glad to say now you can do this by just set loading=lazy attribute to the <iframe> (and <img>) elements, for the newest modern browsers:

And there are some lazyload libs for reference, for older browsers. Here is one of them: