Reputation: 2919
We have a .aspx file which has about 400 lines of javascript code. Is it a good idea to have such huge code in its own file? What is the performance difference in having huge javascript code in aspx as against the .js file?
Please advise
Upvotes: 1
Views: 462
Reputation: 2681
for including js file in aspx, you generally use a string builder, If it so big you need a lot of codes in aspx page. Dont waste client side scripts in server side space. Just use it as an external js file.
Upvotes: 0
Reputation: 17957
Not sure, but it seems like it would be easier to compress the JS code when it's in a separate file.
Upvotes: 0
Reputation: 1259
If you move that logic into a .js file (which I recommend), the browser can cache the JS file, making your page load faster.
Also, the logic (functions) in that JS file could then be used from other pages.
Upvotes: 4
Reputation: 159865
You'll want it in a separate file for two reasons:
.js
file to keep your code DRY. .js
file for caching.Upvotes: 1
Reputation: 9664
If it is in its own file, then clients will only have to download it once, rather than parse it out of the page every time.
Upvotes: 4