shinsenter / defer.php

🚀 A PHP library that focuses on minimizing payload size of HTML document and optimizing page speed.
https://github.com/shinsenter/defer.php
MIT License
40 stars 6 forks source link

Add Deffer inline #21

Closed BlackKite84 closed 5 years ago

BlackKite84 commented 5 years ago

DeepL Translation: Can you insert an option for deffer_min.js. The one that inserts the script inline of HTMl and not external?

Kannst du eine Option für deffer_min.js einfügen. Die den den Script inline des HTMl einfügt und nicht externe?

shinsenter commented 5 years ago

@BlackKite84 yes, there is an option called append_defer_js to make defer.js script inline. Just $defer->append_defer_js = true.

BlackKite84 commented 5 years ago

plz check polyfill?

https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver / Disable minification (remove .min from URL path) for more info /

shinsenter commented 5 years ago

It is an external js file which is cached on your browser in the first request. Your browser does not download it later unless you clear browser data.

Polyfill script should not be inlined because its content is automatically generated, that means the js file is changed on different browsers.

shinsenter commented 5 years ago

Back to your first question, we should not inline external script files, because inlining scripts does not take advantages of browser caches. Processing external files on-the-fly may make your server heavier and your HTML file (which is not cached by browser as default) bigger. Downloading bigger file means it may be slower and use much more bandwidth.

BlackKite84 commented 5 years ago

i need a local version, dont wont externel request

shinsenter commented 5 years ago

@BlackKite84 So you need to download below script files and load it from your local environment.

https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@1.1.5/dist/defer_plus.min.js https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@1.1.5/dist/polyfill.min.js