calling external js files

#1
[eluser]shobekhan[/eluser]
Is it compulsory in code igniter to have the css, js in views include rather than an external css or js file. If I keep the javascript code in external js or style sheet in css file the website runs much slow rather than it being included in a views.

To be precise what I am trying to ask

is slower than

embedding the javascript code in views

#2
[eluser]Josh Giese[/eluser]
[quote author="shobekhan" date="1199831484"]If I keep the javascript code in external js or style sheet in css file the website runs much slow rather than it being included in a views.
[/quote]

The overall page weight would be the same if the files was included in the view, or called externally.

the only slow down that I would think would come from having to open several connection to download each js file, and css file. This speed difference would be so small that I doubt that it would really be noticeable.

The better point is for maintanability and code reuse ability. Separate files are the way to go.

What if you have one JS function you need on several views. if you update that function you have to update each view. if it is external, you update one JS file.

I say separate files are the way it should be done. Much cleaner.

#3
[eluser]Craig A Rodway[/eluser]
Including CSS and Javascript code is more efficient in the long run than having it all embedded in pages - from developer perspective and also the user.

Firstly, you can modularise CSS and JS and, with some PHP magic, only include the desired scripts as and when you need them. Secondly and probably more importantly, browsers usually cache included files. So your 10KB+ of CSS/JS is cached instead of being downloaded on EVERY page view if you wrote it embedded in your page.

The less the browser has to download, the better - the overhead of making separate requests isn't usually that much compared to the size of the file downloaded so don't worry about that.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.