Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Head inline script converted into external JS file #82

Open
cristi-contiu opened this issue Aug 10, 2017 · 6 comments
Open

Head inline script converted into external JS file #82

cristi-contiu opened this issue Aug 10, 2017 · 6 comments

Comments

@cristi-contiu
Copy link

cristi-contiu commented Aug 10, 2017

EXPLANATION OF THE ISSUE

I have noticed a small issue with the compress_combine_head_js option ( htmlc_compress_combine_head_js in WP Admin, as I use this library via your excellent CometCache plugin): When there is an inline script present in the head, it will convert it to an external JS file which requires an render-blocking HTTP request.

STEPS TO REPRODUCE THE ISSUE

Add a inline script to HEAD section, for example
<script> var wp_ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>'; </script>

BEHAVIOR THAT I EXPECTED

I would expect the HEAD external JS (scripts with "src") to be combined/compressed/minified, but the inline scripts (like to one above) to be ignored (maybe minified inline, via different option).

BEHAVIOR THAT I OBSERVED

The above script will be converted to:
<script type="text/javascript" src="http://example.com/wp-content/cache/zencache/htmlc/public/example-com/f/f/d/0/b/b4d1c8d399d0056c01f51915b7df5a3d-compressor-part.js?iv=1"></script>

Converting the (usually small) inline JS script to an external JS file which requires an extra HTTP request to download totally overrides any performance benefit.

@cristi-contiu cristi-contiu changed the title Head inline script converted into external (blocking) JS file Head inline script converted into external JS file Aug 10, 2017
@raamdev
Copy link
Contributor

raamdev commented Aug 19, 2017

@cristi-contiu I noticed the path you posted above contains zencache—are you running the latest version of Comet Cache Pro?

@playinteractive
Copy link

I have the same issue. This is a real problem because it compress code like this:

  t.src=v;s=b.getElementsByTagName(e)[0];
  s.parentNode.insertBefore(t,s)}(window, document,'script',
  'https://connect.facebook.net/en_US/fbevents.js');

@jaswrks
Copy link

jaswrks commented Nov 24, 2017

@cristi-contiu I'll see what we can do to improve the defaults, but you can tune this for your site by adding exclusions. See: Dashboard → Comet Cache → Plugin Options → HTML Compressor → JavaScript Exclusion Patterns

In your case, add this line to the configuration if you want to exclude that snippet.

var wp_ajax_url

@jaswrks
Copy link

jaswrks commented Nov 24, 2017

@playinteractive In your case, add this line:

connect.facebook.net/en_US/fbevents.js

@playinteractive
Copy link

Thanks man, I'll try it.

@cristi-contiu
Copy link
Author

@jaswrks Thank you for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants