views:

35

answers:

3

Is the best approach to loading javascript files to put them in an IFrame and then embed the same in asp.net pages? I have read somewhere that this will help to boost page-loading times.

+2  A: 

Best is to put script references at the bottom of the page. This ensures that all content is loaded before the scripts. Don't use the iFrame unless needed.

DaveDev
i tried adding scripts at the end ..but this is giving me many javascript errors in my pages.
the errors are probably because you are referencing scripted methods before they are loaded. if you move the scripts to the end of the page you also need to move the script calls to after the required script is added - as far as I am aware
Mauro
You need to make your script usage more graceful, see http://www.stevefenton.co.uk/Content/The-Fenton-JavaScript-Ethos/ - the idea is to have no JavaScript mixed into your HTML - that way, you can include it at the top, bottom or wherever (as DaveDev states, adding them to the bottom is considered best practice for page load speeds.)
Sohnee
This is because your content is relying on the scripts. How much JS do you need to load? Could it be having that much of an impact on page loading time? Have you inspected the network traffic with FireBug?
DaveDev
DaveDev
A: 

When looking at page load times, it depends on where your code is stored. If it is in the html then it will be reloaded each time the page is loaded. If you move it out to a js file, it will be loaded the first time and cached after that so then you shouldnt have a problem with affecting the load times.

You can use jQuery's $(document).ready to make sure that all the elements are loaded before running any code.

Steve
A: 

Don't go for the iframe approach. Put the scripts as far away at the bottom of your html as possible and your css as high as possible. Also try to go for unobtrusive javascript if possible. jQuery's great at this so you surely want to take a look into this. The benefit of jQuery is that it's also put on CDN servers which also speeds up performance.

I found these guidelines to be a great help when I was upgrading the performance of one of my former projects at a client: Best Practices for Speeding Up Your Web Site.

Some great tools are also Firebug in combination with YSlow.

XIII