kasparsd / minit

A WordPress plugin to combine CSS and Javascript files.
GNU General Public License v2.0
286 stars 46 forks source link

Could it be that minit finds its js? #38

Closed szepeviktor closed 8 years ago

szepeviktor commented 9 years ago
/* TOC:
 - minit-6eaa7fd0bd3f5cd86377f82510bfed97
*/

/* Minit: http://chrisdry.wp/wp-content/uploads/minit/6eaa7fd0bd3f5cd86377f82510bfed97.js */
/* TOC:
 - jquery-core
 - jquery-migrate
 - jquery
 - aqpb-view-js
 - comment-reply
 - gravity_plug_modernizr
 - gravity_plug_easing
szepeviktor commented 9 years ago

It is a very nifty case: script's src contained ....js?rev=1.2.3 revision number, it's version was not set. // Skip if the file is not hosted locally skipped the script but later it got into add() JS call. Could you check for ? in the script's name and handle it accordingly?

szepeviktor commented 9 years ago

Now I think that even without ? in the url minit minifies it's own generated JS.

szepeviktor commented 9 years ago

I think the header's combined JS gets minified again in the footer. print_scripts_array fires twice.

szepeviktor commented 9 years ago

As I see if the combined script exists then it does not get async_print-ed.

szepeviktor commented 9 years ago

Could it be that if ( ! $script_relative_path ) { should be if ( $script_relative_path ) {?

kasparsd commented 9 years ago

@szepeviktor I have also experienced the issue you described, however it is not related to the external scripts. I am not sure what causes it.

szepeviktor commented 9 years ago

I think the ! in if.

szepeviktor commented 9 years ago

Oh! I see

Print external scripts asynchronously in the footer

So locally hosted scripts are loaded synchronously.

szepeviktor commented 9 years ago

off: I am trying to reach PageSpeed 100 thus loading everything async. This plugin is developed for looking at the HTML source easily: https://wordpress.org/plugins/frontend-debugger/

szepeviktor commented 9 years ago

Could it be that the combined script from the header get re-minit-ed in the footer?

kasparsd commented 9 years ago

@szepeviktor It shouldn't because Minit keeps track of scripts that have been combined and excludes them from being "Minited" again:

https://github.com/kasparsd/minit/blob/master/minit.php#L169

szepeviktor commented 9 years ago

Thank you! I am still in the understanding phase. Would you mind if I put together a PR with only comments?

szepeviktor commented 9 years ago

@kasparsd I think I've found the reason using Frontend Debugger. In the first go scripts registered in the header are minited, then footer scripts. At the next page load these two minited scripts are minited again into one.

Are you planning to work on it?

kasparsd commented 8 years ago

In the first go scripts registered in the header are minited, then footer scripts. At the next page load these two minited scripts are minited again into one.

Exactly, @szepeviktor!

Minit captures all instances of print_scripts_array and creates the Minit version for the files enqueued until that point.

The solution is to do the Minit process right before wp_print_footer_scripts and use print_scripts_array only to capture the registered scripts.

szepeviktor commented 8 years ago

@kasparsd Could you implement that?

kasparsd commented 8 years ago

@szepeviktor Could you test the feature/restructure branch https://github.com/kasparsd/minit/tree/feature/restructure and let me know if it fixes the issue.

szepeviktor commented 8 years ago

I consider this to be solved.