Skip to main content
added 17 characters in body
Source Link
ChrisW
  • 3.4k
  • 2
  • 23
  • 29

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closuresModule Export pattern described in Adequately Good's JavaScript Module Pattern: In-DepthJavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I hesitate because it implies code being loaded into a page, which isn't required by that page. OTOH that's probably what happens when you load any 3rd-party JavaScript library (i.e. you load the whole library but don't use all its functionality).

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closures described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I hesitate because it implies code being loaded into a page, which isn't required by that page. OTOH that's probably what happens when you load any 3rd-party JavaScript library (i.e. you load the whole library but don't use all its functionality).

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic Module Export pattern described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I hesitate because it implies code being loaded into a page, which isn't required by that page. OTOH that's probably what happens when you load any 3rd-party JavaScript library (i.e. you load the whole library but don't use all its functionality).

added 249 characters in body
Source Link
ChrisW
  • 3.4k
  • 2
  • 23
  • 29

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closures described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I hesitate because it implies code being loaded into a page, which isn't required by that page. OTOH that's probably what happens when you load any 3rd-party JavaScript library (i.e. you load the whole library but don't use all its functionality).

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closures described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closures described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?

I hesitate because it implies code being loaded into a page, which isn't required by that page. OTOH that's probably what happens when you load any 3rd-party JavaScript library (i.e. you load the whole library but don't use all its functionality).

Source Link
ChrisW
  • 3.4k
  • 2
  • 23
  • 29

Same JavaScript on different web pages

I have a web site with several web pages. Each page requires some JavaScript: i.e. different JavaScript for different pages, which some JavaScript that's common to every page.

Some of the JavaScript is long (e.g. 4000 lines of code). I coded the JavaScript using the basic anonymous closures described in Adequately Good's JavaScript Module Pattern: In-Depth article.

Anyway, now I'm thinking of using a JavaScript minifier to:

  • Combine several the JavaScript source files into one
  • Include that same, single JavaScript source file on every web page

I hope that doing this would solve two problems:

  • At design time, it's easy to reuse existing JavaScript modules (because the existing modules must be designed as reusable modules, included on and therefore available on every web page)
  • At run-time, it's performant: because the user's browser (which includes mobile browsers) only has one JS source file to download; and that file is presumably already cached in the browser when it loads a second or a third web page (i.e. any page except the first).

Is this a reasonable thing to do? Is it normal, or is it a WTF thing to do? Are there disadvantages I should consider, and are they significant?