简体   繁体   English

动态包含CSS / JS文件的缺点?

[英]Disadvantages of dynamically including CSS/JS files?

What are the specific disadvantages (if any) of dynamically including the CSS and JS files for a website? 动态包含网站的CSS和JS文件的特定缺点(如果有)有什么?

By dynamically, I mean, using the document.write() method generate and tags. 我的意思是动态地使用document.write()方法generate和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? 思考?

  1. Reliability. 可靠性。 People may have JS disabled, etc. 人们可能禁用了JS等。
  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. 某些浏览器(IE)不会为您提供包含文件的错误行号,而只是给您主文件中的document.write行。

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. 我可以想到的缺点是,某些网站性能评估工具(例如PageSpeedYSlow)会警告您页面引用的CSS和JavaScript文件的数量。 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. 现代Web开发实践经常鼓励您合并CSS文件JavaScript文件,以减少呈现页面所需的文件总数并提高网络性能。 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. 一般而言,服务一个大的,ated肿的文件要好于服务十个小的精简文件,因为与从服务器请求文件有关的开销很大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM