demianturner / sgl-docs-tickets-migration-test

0 stars 0 forks source link

makeJsOptimizerLink() adds files more than onces if under global and current #1622

Closed demianturner closed 11 years ago

demianturner commented 11 years ago

I have JavaScript files, which can be included on global level in config, or on manager level. To be sure the manager has the files included, they get added in manager method by $oOutput->addJavascriptFile() even so they may be in global array already.

Unfortunately the current makeJsOptimizerLink() function does not take this into account and just merges the files. This is wrong! The current javascript files should be added by addJavascriptFile() function as well cause there is an in_array() check.

{{{ //$this->aJavascriptFiles = array_merge($this->aJavascriptFiles, $aCurrentFiles); $this->addJavascriptFile($aCurrentFiles); }}}

Thanks! Phil

demianturner commented 11 years ago

[tecodan] I have experienced a similar problem where the same javascript file is loaded multiple times if the Output->addJavascriptFile() is called with the same JS file more than once, regardless of the in_array() checks.

I've concluded that the issue is with the inconsistency of the in_array() check. The check is called prior to the appending of the WEB_ROOT prefix. ie. in the array we may have something like ''http://example.com/js/foo.js'' while its trying to compare it against ''js/foo.js''.

I've attached a patch I've used to solve this issue. It could probably be optimised.

demianturner commented 11 years ago

[lakiboy] I totally agree both of you. Fixed in [3880]