Head inline script converted into external JS file
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 I noticed the path you posted above contains zencache—are you running the latest version of Comet Cache Pro?
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');
@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
@playinteractive In your case, add this line:
connect.facebook.net/en_US/fbevents.js
Thanks man, I'll try it.
@jaswrks Thank you for the tip!