Some css code is not getting minified
-
I have a file here:
https://swinginatthesavoy.com/wp-content/mmr/606372c9-1604040082.min.jswhere a lot of JS code did not get minified. Any reason why that would be?
-
Here is the start of the file:
(function(){document.addEventListener('DOMContentLoaded',function(event){wpcf7_recaptcha.execute=function(action){grecaptcha.execute(wpcf7_recaptcha.sitekey,{action:action}).then(function(token){var event=new CustomEvent('wpcf7grecaptchaexecuted',{detail:{action:action,token:token,},});document.dispatchEvent(event)})};wpcf7_recaptcha.execute_on_homepage=function(){wpcf7_recaptcha.execute(wpcf7_recaptcha.actions.homepage)};wpcf7_recaptcha.execute_on_contactform=function(){wpcf7_recaptcha.execute(wpcf7_recaptcha.actions.contactform)};grecaptcha.ready(wpcf7_recaptcha.execute_on_homepage);document.addEventListener('change',wpcf7_recaptcha.execute_on_contactform);document.addEventListener('wpcf7submit',wpcf7_recaptcha.execute_on_homepage)});document.addEventListener('wpcf7grecaptchaexecuted',function(event){var fields=document.querySelectorAll("form.wpcf7-form input[name='_wpcf7_recaptcha_response']");for(var i=0;i<fields.length;i++){var field=fields[i];field.setAttribute('value',event.detail.token)}})})();var $j=jQuery.noConflict();$j(document).ready(function(){if(typeof oceanwpLocalize==='undefined'){return!1} var qv_modal=$j('#owp-qv-wrap'),qv_content=$j('#owp-qv-content');/** * Open quick view. */ $j( document ).on( 'click', '.owp-quick-view', function( e ) { e.preventDefault(); var $this = $j( this ), product_id = $j( this ).data( 'product_id' ); $this.parent().addClass( 'loading' );
Hi, It looks like that file is now minified. Is that right?
Hi, not quite. I installed java on the server, so it is now using closure-compiler.jar instead of MatthiasMullie\Minify\JS.
The minification is not happening with the latter.
Ahh, my guess is that MatthiasMullie Minify was failing due to something in your javascript. There would have been errors in the logs if it couldn’t complete a minify. Do you know if this was the case?
Closure is more reliable and will do a better job so I think you are best to stick with it.
Sorry for the late reply. Do you mean the WP debug.log file? I did not see any errors in that log.
I mean in the MMR settings. You can expand each merge and it should say if the minification was successful or not.
If it says ‘unminified version used’, does that mean it was not able to minify it?
If not, what does an error look like?aaah, do your scripts that you want to minify have a .min.js extension? MMR doesn’t bother minifying these as it assumes they are already minified.
The comment suggests that if a script comes with a .js and .min.js version, it picks the .js unminified version. Right?
Here is an example file generated:
https://wednesdaynighthop.com/wp-content/mmr/bb8fdbea-1605740607.min.jsIt does not look fully minified to me. For instance, it has comments:
/*! * WPBakery Page Builder v6.0.0 (https://wpbakery.com) * Copyright 2011-2020 Michael M, WPBakery * License: Commercial. More details: http://go.wpbakery.com/licensing */
and plenty of variable declarations that look nowhere like minified code I’ve seen before (where variables are usually abbreviated to the least number of letters possible).
var this_element=jQuery(this),sliderTimeout=1e3*parseInt(...
I just tried Matthias’s public portal: https://www.minifier.org/
And I see the same result. Which is reassuring and still odd because it claims:
This minifier removes whitespace, strips comments, combines files, and optimizes/shortens a few common programming patterns. And it comes with a huge test suite.
which it clearly does not in this case, at least for whitespace and comments.
Just read that the library does not do ‘obfuscation’ so does not change variable names, so that makes sense. Still confused as to why comments are left in the minified file though. Maybe it does not support multi-line comments?
I totally get now why this library runs much faster and with lower CPU usage compared to the Java Closure compiler, which parses the code as a language.
If I find again a big chunk of clearly non-minified code, I will report the issue to Matthias’s github repo.
Yes, MMR will look for a .js first.
I believe the reason the comments aren’t stripped is for legal reasons. I think when a comment has an exclamation mark then it means that the comment should stay even if its being minified.. /*!
I think Minify and Closure both respect this.
- The topic ‘Some css code is not getting minified’ is closed to new replies.