1

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

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

1

You'll want it in a separate file for two reasons:

  1. If you need to reuse any of that code, it would be better to have it in a .js file to keep your code DRY.
  2. If it is not updated as often as the page is updated (i.e., on every postback) then it is better to have it in a .js file for caching.

2 Comments

@Sean----I agree with you and others about browser caching the js file. I am marking your answer as accepted because you also mentioned DRY.
Also Visual Studio will only debug JavaScript in a js file. It will not work with inline JavaScript on an aspx page.
0

Not sure, but it seems like it would be easier to compress the JS code when it's in a separate file.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.