0

What are the specific disadvantages (if any) of dynamically including the CSS and JS files for a website?

By dynamically, I mean, using the document.write() method generate and tags.

I'd like to use this technique on a very large, high-traffic website, since it allows me to easily manage which files are downloaded for which site sections, and to switch on a compressed mode in which only minified files are downloaded.

Thoughts?

0

2 Answers 2

2
  1. Reliability. People may have JS disabled, etc.
  2. Debugging. Some browsers (IE) don't give you the included file's line number on an error, but simply the document.write line in the main file.
Sign up to request clarification or add additional context in comments.

1 Comment

Good points. Although regarding point 1, reliability of Javascript wouldn't be affected, only CSS. If we assume that all our users have Javascript turned on, I don't believe it would matter whether we used the dynamic or traditional method.
2

The advantages are that you can manage and organize your code more easily and you're able to load only those scripts on the page that are absolutely necessary.

The disadvantage, one that I can think of, is that some website performance measuring tools such as PageSpeed and YSlow will warn you about the number of CSS and JavaScript files referenced by a page. Modern web development practices often encourage you to Combine CSS files and Combine JavaScript files to reduce the total number of files required to render a page and improve network performance. Generally speaking, serving one big, bloated file is better than serving 10 small lean-and-mean files because of the overhead associated with requesting a file from the server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.