Subscribe via
Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]
Print
Author Topic: Minified JS placement  (Read 830 times)
bobmarl33
Newbie
*
Posts: 7


View Profile Email
« on: February 07, 2010, 05:09:08 PM »

This patch defers minified JavaScript injection to the end of head, ensuring that any excluded dependencies such as jQuery have been loaded first.

--- wp-minify.old       2010-02-07 18:23:34.000000000 -0500
+++ wp-minify.php       2010-02-07 19:04:05.000000000 -0500
@@ -575,7 +575,7 @@
         }

         // HTML5 has <header> tags so account for those in regex
-        $content = preg_replace('/<head(>|\s[^>]*?>)/', "\\0\n$js_tags", $content, 1); // limit 1 replacement
+        $content = preg_replace('/<\/head(>|\s[^>]*?>)/', "$js_tags\n\\0", $content, 1); // limit 1 replacement
       }
       return $content;
     }
Logged

krisnelson
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #1 on: February 07, 2010, 06:08:42 PM »

Funny, after struggling with jquery functioning correctly with WP Minify (I wanted to load it from Google's servers instead of mine), I made almost exactly this modification myself just today to fix the problem!

Thus, I would love to see this patch added to the official WP Minify, or perhaps an option to put it at the beginning or end of <head>.

Kris
Logged

Thaya
Administrator
Sr. Member
*****
Posts: 420



View Profile WWW Email
« Reply #2 on: February 17, 2010, 12:33:51 PM »

It turns out that this is not always desirable. For example, if you have an excluded JS that requires a particular library that has been minified (such as jQuery), then the excluded script will not work.
Logged

krisnelson
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #3 on: February 17, 2010, 01:06:16 PM »

Makes sense that it would not always be desirable. Perhaps an option to do this?

(Personally, I don't minify jquery, but rather pull it from Google's CDN instead.)

Thanks for considering it, anyway! (For now I'll just hack the code myself for each update.)

And thanks for a great plugin, too.

Kris
Logged

Thaya
Administrator
Sr. Member
*****
Posts: 420



View Profile WWW Email
« Reply #4 on: May 02, 2010, 06:56:12 PM »

Version 0.8.0 has what you want :)
Logged

Pages: [1]
Print
Jump to: