feat(lazy_loading): remove loading-attribute-polyfill due to requirement of inline script

* it requires 'unsafe-inline' for script-src policy
This commit is contained in:
curben 2019-08-30 08:23:06 +01:00
parent dd9d45ebb1
commit b6acf222e2
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
3 changed files with 2 additions and 13 deletions

View File

@ -47,7 +47,6 @@ hexo.extend.tag.register('cloudinary', (args) => {
if (fileName.endsWith('.png') || fileName.endsWith('.webp')) {
return `<a href="${legacyLink}">
<picture>
<noscript class="loading-lazy">
<source type="image/webp"
srcset="${modernLink}&w=320 320w,
${modernLink}&w=468 468w,
@ -58,8 +57,8 @@ hexo.extend.tag.register('cloudinary', (args) => {
(max-width: 768px) 768px,
800px">
${img}
</noscript></picture></a>`
</picture></a>`
} else {
return `<a href="${legacyLink}"><noscript class="loading-lazy">${img}</noscript></a>`
return `<a href="${legacyLink}">${img}</a>`
}
})

View File

@ -45,11 +45,6 @@
<%/* Fallback function for SRI */%>
<%- addJs('/js/sri.min.js') %>
<%/* Polyfill for <img loading="lazy"> */%>
<% if (is_post()) { %>
<%- addJs({ src: 'https://cdn.statically.io/gh/mfranzke/loading-attribute-polyfill/65fca968/loading-attribute-polyfill.min.js', 'data-sri-fallback': '/js/loading-attribute-polyfill.min.js', integrity: 'sha384-8jTDDmc3bqX0o3YImTHy8PKVewXMkZLzo1aXpDhU3ezHoimhZxF5psMm7PjKnSt9', crossorigin: 'anonymous'}) %>
<% } %>
<%- addCss('/css/typing.css') %>
<% if (theme.icons) { %>

View File

@ -1,5 +0,0 @@
/*
* Loading attribute polyfill - https://github.com/mfranzke/loading-attribute-polyfill
* @license Copyright(c) 2019 by Maximilian Franzke
*/
!function(e,t){"use strict";var r,a,o={rootMargin:"256px 0px",threshold:.01,lazyImage:'img[loading="lazy"]',lazyIframe:'iframe[loading="lazy"]',loadingSupported:"loading"in HTMLImageElement.prototype&&"loading"in HTMLIFrameElement.prototype};"undefined"!=typeof NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),"IntersectionObserver"in window&&(r=new IntersectionObserver(function(e,t){e.forEach(function(e){if(0!==e.intersectionRatio){var r=e.target;t.unobserve(r),i(r)}})},o)),a="requestAnimationFrame"in window?window.requestAnimationFrame:function(e){e()};var n="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";function i(e){var t,r,a=[];"picture"===e.parentNode.tagName.toLowerCase()&&(t=e.parentNode,(r=t.querySelector("source[data-lazy-remove]"))&&t.removeChild(r),a=Array.prototype.slice.call(e.parentNode.querySelectorAll("source"))),a.push(e),a.forEach(function(e){e.dataset.lazySrcset&&(e.setAttribute("srcset",e.dataset.lazySrcset),delete e.dataset.lazySrcset)}),e.setAttribute("src",e.dataset.lazySrc),delete e.dataset.lazySrc}function d(){document.querySelectorAll("noscript."+e).forEach(function(e){var t=e.textContent||e.innerHTML;o.loadingSupported||(void 0===r?t=t.replace(/(?:\r\n|\r|\n|\t| )src=/g,' lazyload="1" src='):("picture"===e.parentNode.tagName.toLowerCase()&&(t=function(e){return'<source srcset="'+n+'" data-lazy-remove="true"></source>'+e}(t)),t=function(e){return e.replace(/(?:\r\n|\r|\n|\t| )srcset=/g," data-lazy-srcset=").replace(/(?:\r\n|\r|\n|\t| )src=/g,' src="'+n+'" data-lazy-src=')}(t)));var a=document.createElement("div");for(a.innerHTML=t;a.firstChild;)o.loadingSupported||void 0===r||!a.firstChild.tagName||"img"!==a.firstChild.tagName.toLowerCase()&&"iframe"!==a.firstChild.tagName.toLowerCase()||r.observe(a.firstChild),e.parentNode.insertBefore(a.firstChild,e);e.parentNode.removeChild(e)}),window.matchMedia("print").addListener(function(e){e.matches&&document.querySelectorAll(o.lazyImage+"[data-lazy-src],"+o.lazyIframe+"[data-lazy-src]").forEach(function(e){i(e)})})}/comp|inter/.test(document.readyState)?a(d):"addEventListener"in document?document.addEventListener("DOMContentLoaded",function(){a(d)}):document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&d()})}("loading-lazy");