bassjobsen / wp-defer-loading

Defer loading javascript for WordPress. Without any additional library. Just the way Google ask you to do it.
4 stars 2 forks source link

javascript shows on the top of each page #11

Open bassjobsen opened 10 years ago

bassjobsen commented 10 years ago

It spews out what should be Javascript as visible text at the top of each page. Looking at the page source, there are superfluous script tags, but I haven't had a chance to look at it any further.

Original posted here: http://wordpress.org/support/topic/plugin-could-not-be-activated-because-it-triggered-a-fatal-error-100 by @mattday

bassjobsen commented 10 years ago

The plugin use these hooks:

remove_action( 'wp_head','wp_print_head_scripts',9); remove_action( 'wp_footer','wp_print_footer_scripts',20); add_action('wp_head', array( $this, 'defer_loading_code'),99); add_action( 'defer_loading_scripts','wp_print_head_scripts',1);

So check the theme or plugin also invoke on wp_print_head_scripts

bassjobsen commented 10 years ago

@mattday wrote: The theme was just a very slightly modified version of Twenty Twelve.

I can't reproduce this problem at the moment. Installing Twenty Twelve unmodified doesn't show the error, see: 2012

One of the used plugin cause the error maybe.

mattday commented 10 years ago

It is possible that another plugin may be responsible, although my Apache development server with mostly the same plugins does not cause the error either. Will need to test it on nginx.

mattday commented 10 years ago

I have reproduced the problem on a fresh install of WordPress. It occurs when the following plugins are active together:

WP Defer Loading Use Google Libraries UK Cookie Consent

The script shown is actually different from before, but the reason it is output on the page is likely to be the same. clipboard01

bassjobsen commented 10 years ago

@mattday thank you very much for posting! This helps. I'm investigate the plugins you mention. Till now i didn't found the top page output.

But for now i can tell you the UK Cookie Consent won't work without some changes, see issue #12

bassjobsen commented 10 years ago

@mattday Use Google Libraries definitely cause the output problem, see also issue #13. Do you expect a huge profit when using defer loading with CDN? See also issue #2

mattday commented 10 years ago

Thanks for investigating. I have just checked the Use Google Libraries code and agree. As I understand it, the method remove_ver_query (line 444) gets called as a filter (via script_loader_src hook) so should only process the string passed to it, not echo anything to the page.

I don't expect much benefit from the combination, but it does always make sense to me to use a CDN for jQuery instead of hosting it.