I have roughly 700 lines of javascript code going on a new site with ASP.NET. I have a question, and sadly cannot perform the competition at this moment.

Would be be better and faster to just include a javascript file through masterpages, or would it be better to use stringbuilder to append each line, then register the script?

Example:

Dim str As New StringBuilder()

str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")
str.AppendLine("....")

RegisterScript("scriptname", (str).ToString(), True)
'Custom function that creates the script, checks for
'registration, then adds the script to the page with tags (if needed).

** WRONG FORUM **
** Admin, please move to forum ASP.NET, Thank you **

Oh no, I know all this already.

What I was asking is more of whether or not I should use an included javascript file, or use stringbuilder.

<script .. src="file.js"></script>

or the append line method. The reason I ask is that I have a JS file over 700 lines long, and was wondering what would be better. But thank you for pointing that article out, was helpful in an instance.

Before Creation 	 0.00657039594771528	   0.006289
script1 done             0.0916923963414444  	   0.085122
Script2 done    	 0.0918021380114182	   0.000110
After Creation	         0.0918377436198702	   0.000036
Before Replace       	 0.0918706793701585	   0.000033
Before Censor	         0.0921031770187209	   0.000232
After Censoring	         0.128371457766306	   0.036268
After Writing	         0.128624754309927	   0.000253

Before Creation (Before anything is put on the page)
script 1 done (Register 300 line script)
script 2 done (register remaining lines)
After Creation (after scripts created)
Before Replace (before I do a replace for the word "car" to "p*ssy" on a 10,000 char string)
Before Censor (After replace, but before I censor)
After Censoring (after I censored a 10,000 character string)
After Writing (after writing a 10,000 cahracter string)

Seems fast.
Sad, but almost all of the time was for putting the script onto the page. Let me see the difference with including it.

Quicker to include the file, by far (at least under first load). Under first load, it takes .128 seconds to load a 10,000 char file with 90 replacements within 250 searches, all while registering a 700 line script.

Takes .015 seconds to do all that, except include the file instead of appending it with register script.

solved.

if you have your code inline, with "view source" you show every "logic" you have there. if you put your js file into a folder you can secure it and this way your "logic" will be secure.

If anyone else is concerned or would like some extra knowledge:

Replacing 7,932 occurances in a string with styled format, in a string of 380,000 characters, it took this long:

1.671838 seconds.

This article has been dead for over six months. Start a new discussion instead.