0

i have one master page for my website. i place simple script tag before closing body tag. like

<body>
here will be content placeholder 
<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
</body>

in my content page i have script tag like

<script type="text/javascript">
$("a.foo").click(doSomething);
function doSomething()
{
 return confirm("About to visit " + this.href + ", continue?");
}
</script>

but i want this script tag should be place at runtime just before the closing of body tag. how could i do this....do i need to write any code ? please help me with best suggestion.

thanks

Keith Costa
  • 1,783
  • 11
  • 35
  • 68
  • have you tried placing code at bottom of page? What type of javascript, functionality of that function?? – Emaad Ali Oct 12 '11 at 12:34

1 Answers1

0

Don't bother with this. Put the jQuery library on the head section of the master page. Use a CDN so that it is cached, then put your script anywhere you want inside your content place holder.

If you can't use a CDN, then configure your web server to cache Javascript files. It's very simple. See here.

Community
  • 1
  • 1
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • A CDN is of use if you want to speed load time by reducing latency. The JavaScript being in the head will still block the page moving it to the bottom helps reduce the impact of the blocking. Though we're talking asp.net which bakes in lots of bad practice from a performance point of view so the whole debate may be questionable. – Andy Davies Oct 16 '11 at 18:14
  • @AndyDavies I agree, but the OP is complicating things more than it needs to. A CDN will consistently return 304 HTTP Responses so the blocking will happen only once. I think that's not the end of the world. – Icarus Oct 16 '11 at 18:21
  • The blocking from loading and parsing will happen everytime - remember by default it's done on the UI thread. If the file is cached it'll obviously reduce the loading time but depending on how it's cached the latency of the roundtrip will still be there (CDN should minimise though). – Andy Davies Oct 17 '11 at 20:47