A Parser-blocking, cross-origin script is invoked via document.write
-
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:
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/adminsetup.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.
- The topic ‘A Parser-blocking, cross-origin script is invoked via document.write’ is closed to new replies.