• mehedi_doha

    (@mehedi_doha)


    I had a bad experience recently with this plugin where wp_enqueue_media() is not working from frontend having ‘Optimize js code’ is enabled.
    I used below code to enqueue my wp_enqueue_media:

    function add_my_scripts() {
        wp_enqueue_media();
    
     }
    
     add_action('wp_enqueue_scripts', 'add_my_scripts');

    Do you have a proper solution for this ?

    Thanks & Regards,
    M

    https://wordpress.org/plugins/autoptimize/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Frank Goossens

    (@futtta)

    well, wp_enqueue_media adds javascript to your page (did a quick search, but couldn’t find which one). exclude that JS from optimization (adding it and any dependancies) to the comma-seperated exclusion list and it’ll work.

    hope this helps,
    frank

    Thread Starter mehedi_doha

    (@mehedi_doha)

    Hi Frank,
    Thanks for your quick reply. For your kind reference, when we enqueue default wp-media (right now using version 4.1) its added ‘plupload.full.min.js’ file in footer which locates at : wp-includes/js/plupload/ folder.

    I tried with your ‘exclude’ comma-seperated exclusion from admin settings but no luck 🙁

    Would you please just add below code in functions.php file to any site and try to check console through firebug from front-side:

    function add_my_scripts() {
        wp_enqueue_media();
    
     }
    
     add_action('wp_enqueue_scripts', 'add_my_scripts');

    Yesterday, i opened a ticket in stackoverflow where you can see the error i am facing: CLICK HERE

    Regards,
    M

    Plugin Author Frank Goossens

    (@futtta)

    So, I’ve had a first (and second) look at this.

    What I learned up until now;
    * wp_enqueue_media adds a huge amount of JS (and inline script of type “text/html”!) to a page.
    * I have not yet been able to autoptimize a page with it, although I’m pretty sure I’ll crack that later.
    * but even when succeeding in doing so, there’ll be a huge amount of JS you’ll have to exclude, which will most probably make the page perform poorly anyhow.

    So my advice; don’t do wp_enqueue_media on each page, but do it on one page (or a limited number of pages) instead and exclude that/ those page(s) from being autoptimized (using the API).

    I’ll look into this some more and will report back here if I have more findings to share 🙂

    frank

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_enqueue_media not working when enable Optimize js code’ is closed to new replies.