AlwaysAProgrammer
AlwaysAProgrammer

Reputation: 2919

javascript code in aspx file

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

Answers (5)

Andrew Collins
Andrew Collins

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

Vadim
Vadim

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

Marcie
Marcie

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

Sean Vieira
Sean Vieira

Reputation: 159865

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.

Upvotes: 1

Aaron Daniels
Aaron Daniels

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

Related Questions