SYSK 256: JavaScript: Embed or Separate? Pros & Cons of both scenarios.

Have you considered the pros & cons of writing your javascript code right in you aspx pages vs. packaging it into external .js script files?  Here is my attempt at such analysis:


Benefits of embedding javascript into .aspx pages:

-      Simplicity – no other files to create, manage & deploy

-      Containment (of sort) – all functions required by the page are right there… in the page


Benefits of keeping javascript in separate .js files:

-          Increases cacheability

-          Compression and bandwidth reduction

-          Can create & easily switch between debug and release script versions

-          Encourages to create reusable functions, rather than hardcoding page specific logic/control ids. 

-          Allows for logical grouping of related functions per .js file (regardless of the pages they are used on)

If you can think of other points, don’t hesitate to share them with others by posting them as a comment at the bottom of this page.


NOTE: To avoid SPAM, I configured this blog to require approval for all comments.  I try to check for pending comments several times/day, and, at a minimum, once/day. 



Comments (1)

  1. LiQ says:

    Comming versions of ASP.NET should have some smart function that creates a .js-file and stuffs it with all the JavaScript that gets written directly on the page now. Next to every Control that has any postback-function seems to have a <script>-tag next to it.

Skip to main content