• Resolved rrecurse

    (@rrecurse)


    On Chrome browsers, a warning occurs:

    A Parser-blocking, cross-origin script is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity.

    Script in question is:

    https://www.google.com/uds/api/visualization/1.0/1195ca6324d5ce101c2f520f3c…mat+en,default+en,ui+en,geochart+en,table+en,orgchart+en,corechart+en.I.js

    I’ve tried to correct this by loading the googlejsapi Asynchronously like this in setup.php:

    
    add_filter( 'script_loader_tag', function ( $tag, $handle ) {
        if($handle == 'googlejsapi') {
            return preg_replace("/(><\/[a-zA-Z][^0-9](.*)>)$/", " async$1", $tag);
        } else {
            return $tag;
        }
    }, 10, 2);
    

    But this requires a new callback function parm be placed on the script above, for example, in

    /google-analytics-dashboard-for-wp/front
    /google-analytics-dashboard-for-wp/admin

    setup.php

    this:

    wp_register_script( 'googlejsapi', 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27', array(), null );

    becomes this:

    wp_register_script( 'googlejsapi', 'https://www.google.com/jsapi?callback=gadwp_drawFrontWidgetChart&autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27', array(), null );

    But then this requires an additional callback function to work. I’ve tried to target several of the existing functions, but none i tried worked (function not defined errors when loading async).

    For cross browser compatibility, perhaps the author can chime in here and recommend a fix or release an update to correct this issue.

    Looking forward to a response.

Viewing 1 replies (of 1 total)
  • Hi,

    That’s an issue I’m aware about and quite difficult to resolve. Eventually I will probably end-up adding an option allowing users to choose the loading method. While autoloading is more reliable is quite a problem for users with slow internet connections. On the other hand using a callback can generate issues (as you already noticed) for the others.

    • This reply was modified 7 years, 5 months ago by Alin Marcu.
Viewing 1 replies (of 1 total)
  • The topic ‘A Parser-blocking, cross-origin script is invoked via document.write’ is closed to new replies.