Subscribe via
Welcome, Guest. Please login or register.
Did you miss your activation email?
 OMNINOGGIN ForumPlugin SupportWP MinifyLoad minified JavaScript in Footer
Pages: [1]
Print
Author Topic: Load minified JavaScript in Footer  (Read 1038 times)
kiranv
Newbie
*
Posts: 3


View Profile Email
« on: February 11, 2010, 06:34:08 AM »

To load minified js file at the bottom of body tag replace the existing wp-mnify.php with attached wp-minify.php file .Thaya Kareeson in future versions we expect you to add this patch  and keep an checkbox in admin side  to load minified js in footer or head part.
Logged

kiranv
Newbie
*
Posts: 3


View Profile Email
« Reply #1 on: February 15, 2010, 02:50:49 AM »

added option in admin page to load minified javascript in footer .check the attached modified wp minify plugin
Logged

codeimpossible
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #2 on: February 16, 2010, 12:29:33 AM »

It looks like your changes will lead to the javascript being embedded twice in the output. Once in the header and once in the footer. The problem is that the $content var is being modified in the inject_js() and post_content() functions.

i think instead of having the footer insert code in the post_content() function the change should be made solely in the inject_js() function.

Take a look at the attached wp_minify.php file which I've been using for the past year on my own site and it appears to be working just fine.

Note that this file will ONLY embed the javascript at the end of the content. It doesn't provide any configuration options.

Logged

kiranv
Newbie
*
Posts: 3


View Profile Email
« Reply #3 on: February 16, 2010, 01:50:54 AM »

As you said the javascript will not be embedded twice in my code .
If you look into inject_js function I am returning $js_tags variable instead of returning $content and in post_content function based on admin settings javascript will be loaded either in head tag or in footer section.
It is working fine in our website take a look at www.qontext.com

Logged

codeimpossible
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #4 on: February 16, 2010, 05:51:36 AM »

ah, my mistake! I was thinking that $content was a global.
Logged

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



View Profile WWW Email
« Reply #5 on: February 17, 2010, 12:31:35 PM »

Are you guys sure you want to put JavaScript at the bottom of the page? What if you have calls to libraries such as jQuery and your move the minified JS to the bottom. That will definitely kill all of your JavaScript code that needs to refer to that library. The idea of the checkmark is good, but it sounds too much like a hack to me and it will only bring in more support requests. I am hesitating giving users this option because I don't want to deal with people asking me to help them debug the plugin since they can't get it to work when they place JS in the footer (but it works fine in the header).

I'm looking into ways of categorizing which scripts should go in the footer and which scripts should go in the header.
« Last Edit: February 17, 2010, 12:36:59 PM by Thaya » Logged

krisnelson
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #6 on: February 17, 2010, 01:08:04 PM »

Perhaps there could be an "Advanced Options" screen where some of these potentially problematic -- but very useful to some of us -- options are put? (Just a thought.)
Logged

codeimpossible
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #7 on: February 18, 2010, 07:36:55 AM »

On my blog I've included jquery from the google CDN and have added the following to my ignore list in wp-minify:

google.com
microsoft.com

So when I run wp-minify as it comes OOTB, it inserts the minified scripts as the first child in the <head>. This "breaks" the js on my site.

I think that adding an advanced section of options as others have suggested with a disclaimer that "here be dragons" and all who touch these options do so at their own peril would be perfect. It would be worth if just to be able to have this feature without having to alter the plugin every time an update is released.

 

Logged

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



View Profile WWW Email
« Reply #8 on: February 18, 2010, 09:44:24 AM »

I guess checkboxes for advanced options should be sufficient for now. I'll look into adding these options it in 0.7.0. Thanks guys!
Logged

Pages: [1]
Print
Jump to: