• Resolved eddr

    (@eddr)


    Hi

    There are two options currently:
    1. Load JS file late + “defer” attribute
    2. Load JS early, with no “defer”

    Wouldn’t it be faster to load it early, but with a “defer” attribute? that way the downloading will start early, but the executing late, not interfering with DOM building. Wouldn’t it be useful for some?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    although not available by default, this can be accomplished by ticking the “force JS in head”-option and using this code snippet to add the defer attribute;

    
    add_filter('autoptimize_filter_js_defer','force_defer');
    function force_defer($in) {
        if ($in === "") {
           return "defer ";
        }
        return $in;
    }

    frank

    Thread Starter eddr

    (@eddr)

    Great, thanks, but what do you think about the logic? couldn’t it have some advantage?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    could be 🙂

    why don’t you test and share your findings? B-)

    Thread Starter eddr

    (@eddr)

    Seems like it works faster, indeed loading while not blocking
    can’t wait for the next version!
    I really want to be able to combine files in groups, allowing for an “above the folder” combined css file, while the rest of it loads later – can it be done with current hooks?

    • This reply was modified 6 years ago by eddr.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    typically above-the-fold CSS is inline so ensure it’s not render-blocking. moreover it is not a combination of a number of files, but a combination of specific selectors from a number of files. we are currently working on an integration with criticalcss.com for a fully automated creation and injection of rule-based critical css (as the critical css for your homepage is different from the one on a blogpost is different from an archive page is …).

    what can be done, using the API, is creating a whitelist of to-be-aggregated CSS-files (whereas the logic is the UI to exclude is a blacklist). using that whitelist only the files listed will be aggregated & minified. you can combine that with another filter (which minifies non-aggregated files). let me know if you’d like example code 🙂

    Thread Starter eddr

    (@eddr)

    Thanks

    I’ll try

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Load JS early, but with “defer” would be faster, no?’ is closed to new replies.