I want to combine several script/css files for performance.I have read the relevant section in Yii guide,but I have a question.
Each route in an application always loads different js/css assets.So does the scriptMap property of clientScipt has to be configured in every single viewfile?I have a complex application with a my own custom CMS backend-that would be a nightmare.Or should I note down every single js/css file used in my application and combine them in one js/css file that is registered in the main layout ,so that is loaded in every page request?But the latter would mean unnecessary script/css overhead for every page.Not to mention that I would have to track down all the js/assets that every single Yii widget uses.
I have tried out EClientscript extension,it combines only the necessary assets that each request uses,and it does a great job.
I just don’t understand how it would be possible without the use of such an extension to undertake this laborious task of tracking down the js/css assets that are used for every single page request in order to map them to the final combined file in scriptMap.One would need a scriptMap and a combined js/css file for every route of the application…
Last,on corescripts…What is best in terms of performance?To have them loaded from Google ,or from one local combined/minimized file??
I would appreciate if someone could enlighten me on this.
I’m looking for information about script minification too, but I can tell you that using google would be better.
The browsers can only load 2 files from the same server at the same time. Using google CDN you would make the load of the page more concurrent, as it would download one file from there and still be free to download other 2 from your server.
ΙI asked the opinion of experienced Yii developers (from the Development team included),and my conclusion is script optimization is best only for common and most used scriptsOptimizing all scripts in an app would mean one should combine all scripts for every page request (one all.js file for every request),and although theoretically possible ,it would be a nightmare to implement.(and performance gain is not guaranteed…)
Also i decided not to use Google API,cause I want to be on the safe side.What if Google server is down?You need to have a fallback on your hard disk anyway.Again,this is an opinion of an experienced Yii developer.