Google api & minify support

Discuss PivotX 2.0.x here. Non-PivotX related discussions go in The Drain.

Google api & minify support

Postby ilvalle » Fri Apr 23, 2010 3:29 pm

Hi,
I tried to replace the jquery local link with the google api
from:
Code: Select all
 <script src="includes/js/jquery.js" type="text/javascript"></script>
<script src="includes/js/jquery-ui.js" type="text/javascript"></script>

to
Code: Select all
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>


And the site works fine but when I enabled the minify support the site doesn't run correctly.
The js are not loaded because they are not requested to the server! The minify request only css files.
Look:
Code: Select all
http://dev.masia5.it/pivotx/includes/minify/?url=&f=pivotx/templates_internal/ui-theme/jquery-ui.css,pivotx/includes/markitup/markitup.css,pivotx/templates_internal/assets/thickbox.css,pivotx/templates_internal/assets/formclass.css,pivotx/templates_internal/assets/pivotx.css,pivotx/templates_internal/assets/pivotx_ie.css


thank in advantage
ilvalle
 
Posts: 26
Joined: Fri Apr 23, 2010 3:15 pm

Re: Google api & minify support

Postby hansfn » Fri Apr 23, 2010 8:36 pm

First of all: What PivotX version are you using? Secondly, the minifier isn't (and shouldn't) minifying external resources.Thirdly, with the current version of PivotX, I'm not able to reproduce the problem - links to external JS files are preserved and PivotX JS files are combined.

PS! Where exactly did you replace the PivotX Jquery URLs with Google?
hansfn
Developer
 
Posts: 3281
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Google api & minify support

Postby ilvalle » Sat Apr 24, 2010 9:41 am

Hi
hansfn wrote:What PivotX version are you using?

PivotX - 2.1.0: beta 3
hansfn wrote:the minifier isn't (and shouldn't) minifying external resources

Yes, I know. I want to minify only the other javascript resources

hansfn wrote:with the current version of PivotX, I'm not able to reproduce the problem - links to external JS files are preserved and PivotX JS files are combined.


Good! But which file have you change?

hansfn wrote:Where exactly did you replace the PivotX Jquery URLs with Google?


I just change the file:
Code: Select all
pivotx/templates_internal/inc_header.tpl


thanks
ilvalle
 
Posts: 26
Joined: Fri Apr 23, 2010 3:15 pm

Re: Google api & minify support

Postby ilvalle » Sat Apr 24, 2010 3:35 pm

Hi.
I found and solved the bug:
Look the file pivotx/objects.php on line 3046
The line code:
Code: Select all
 $this->html = str_replace($this->jsfiles[0], $minifylink, $this->html);
 

is wrong because the $this->jsfiles[0] is not guaranteed that it is set. In my case the position 0 of the array is unset because it is an external resource.
I replace that line with:
Code: Select all
 for($i=0;$i<$count;$i++) {                                               
    if ( isset($this->jsfiles[$i] )) {                                             
        $this->html = str_replace($this->jsfiles[$i], $minifylink, $this->html);
        break;                                                                 
    }                                                                         
}


It is more complex but it now works.
ilvalle
 
Posts: 26
Joined: Fri Apr 23, 2010 3:15 pm

Re: Google api & minify support

Postby hansfn » Sat Apr 24, 2010 7:05 pm

Thx a lot for the bug report (and a suggestion for a fix). A better fix is included in revision 2619.

PS! I wasn't able to reproduce the bug initially because I was testing in the front-end in stead of the back-end.
hansfn
Developer
 
Posts: 3281
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Google api & minify support

Postby ilvalle » Sat Apr 24, 2010 10:35 pm

hansfn wrote:A better fix is included in revision 2619.

Very Good.

Just a question:
what you think about the possibility to add in the configuration panel a checkbox to choose if the site uses the local resource or alternatively uses the external resource?

With external resource I mean the jquery library hosted to google.
ilvalle
 
Posts: 26
Joined: Fri Apr 23, 2010 3:15 pm

Re: Google api & minify support

Postby ilvalle » Wed Mar 30, 2011 5:49 pm

ciao
I made a simple change in lib.php to choose if the jquery library must be taken locally or remotely (google api)
Code: Select all
   
if ($PIVOTX['config']->get('googleapi') == 1) {
        $PIVOTX['paths']['jquery_url'] = fixpath("http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js");
    } else {
        $jquery_filename = getDefault( $PIVOTX['config']->get('jquery_filename'), "jquery-1.5.min.js");
        $PIVOTX['paths']['jquery_url'] = fixpath( $PIVOTX['paths']['pivotx_url'] . 'includes/js/' . $jquery_filename );
    }
ilvalle
 
Posts: 26
Joined: Fri Apr 23, 2010 3:15 pm


Return to 2.x Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron