3

I'm working on a WebForms application that has several pages. Each page currently loads JQuery in a script tag in the head. A colleague I'm working with insists this is WET code and a violation of the DRY principle since each page has to load JQuery individually. He suggests that the site should be refactored as a single page application so JQuery is only loaded once. He suggests content should be toggled between a hidden/unhidden state to simulate going between webpages.

This application will be used by 3 users on an intranet. The size of JQuery is in the neighborhood of 250k.

Can this really be considered a violation of the DRY principle? There's a chance that two webpages could possibly refer to different versions of JQuery, but I wouldn't consider it to be a violation of the principle. The logic seems contorted to me. What do you guys think?

7

A colleague I'm working with insists this is WET code and a violation of the DRY principle since each page has to load JQuery individually.

No.

  1. The jQuery library code is cached by the browser. If it's served from a CDN, it's essentially cached permanently, or until the version changes. So the impact of "code duplication" is effectively zero.

  2. The DRY principle applies to source code that is being duplicated across multiple methods in an application or library, not executable copies of said applications or libraries. You wouldn't say "Windows is not DRY because it runs on millions of computers," would you?

Turning your entire application architecture upside down just to get jQuery to load once is ridiculous. Toggling content between visible and invisible to simulate different pages is even more ridiculous.

You can, of course, create a Single Page Application if that is your goal. But doing so to make sure jQuery only loads once is the tail wagging the dog.

  • 1
    +1 For accenting how ridiculous the idea is. Can't believe people haven't heard about browser caching. – Alternatex Apr 19 '16 at 8:21
  • Thanks for the answer! I couldn't imagine this causing a problem but wanted to do a reality check. In the moment I glossed over the obvious fact that the browser is going to cache the JQuery file. – Narthring Apr 19 '16 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.