简体   繁体   English

与Web服务器有关的静态内容是什么?

[英]What is static content in relation to web server?

Nginx is declared as a considerably faster server than Apache in serving static content . 在提供静态内容方面, Nginx被声明为比Apache更快的服务器。

Is JavaScript code static or dynamic content? JavaScript代码是静态内容还是动态内容?

"Static" means that the data is exactly the same for each and every request, which is opposed to "dynamic" responses which are generated individually for each request by a server side program (eg PHP, Python, Ruby, C#, any CGI script etc.). “静态”是指每个请求的数据完全相同,这与服务器端程序 (例如PHP,Python,Ruby,C#,任何CGI脚本)针对每个请求分别生成的“动态”响应相反等等。)。 In other words, anything that just sits on disk as a file and is served as is is static data; 换句话说,任何只是作为文件放在磁盘上并按原样提供的东西都是静态数据。 anything that invokes a server side program is not. 没有调用服务器端程序的任何东西。

Yes, Javascript files are static data as far as the web server is concerned, since the web server is just serving the Javascript file as is, it doesn't interpret or run it*. 是的,就Web服务器而言,Javascript文件是静态数据,因为Web服务器只是按原样提供Javascript文件,因此它不会解释或运行它。

* Unless it does, of course, via node.js or such. *除非这样做,否则当然是通过node.js等。

Static content is plain files like html, images, css, js 静态内容是纯文本文件,例如html,images,css,js

Pure javascript code files are considered static content when the bytes are served directly from the server without any modification (like templating/transpiling/generation). 当直接从服务器提供字节而不进行任何修改(例如,模板化/编译/生成)时,纯javascript代码文件被视为静态内容。

Static resources can usually be cached. 通常可以缓存静态资源。

Dynamic means the bytes are generated/modified by the server and thus not simply served as-is. 动态意味着字节是由服务器生成/修改的,因此不能简单地按原样提供。 Usually dynamic content is html server-side templates, generated image graphs and such. 通常,动态内容是html服务器端模板,生成的图像图等。

NOTE: it has nothing to do with javascript being a dynamic language 注意:与javascript是动态语言 无关

NOTE: any dynamic changes occuring inside the browser are not considered 注意:不考虑浏览器内部发生的任何动态变化

Static Content 静态内容

Static content is published to regular files eg images, JavaScript, CSS on your server and handled using the simplest methods available to the web server.The content remains the same for every request. 静态内容会发布到服务器上的常规文件(例如图像,JavaScript,CSS)中,并使用网络服务器可用的最简单方法进行处理。每次请求的内容都保持不变。

The advantages of static content are: 静态内容的优点是:

  • it is the fastest and most efficient way to deliver content 这是最快,最有效的内容交付方式

  • it does not require any code to execute or any databases to be 它不需要任何代码来执行或不需要任何数据库
    accessed, which makes it the most secure way to deliver content 访问,这使其成为传递内容的最安全方式

  • it uses simple, clean URLs to address the content 它使用简单,干净的URL来处理内容

  • it takes best advantage of web caching systems, which further boosts performance 它充分利用了Web缓存系统的优势,从而进一步提高了性能

  • it is compatible with every type of webserver technology 它与每种类型的Web服务器技术兼容

    However, it also has the following disadvantages: 但是,它也具有以下缺点:

  • it must be republished when it changes, or your viewers will not see the updates 更改时必须重新发布它,否则观众将看不到更新

  • it cannot display differently to different viewers, depending on 它不能向不同的观看者显示不同的内容,具体取决于
    their login status or other factors 他们的登录状态或其他因素

Dynamic Content 动态内容

Dynamic content is generated for you at the time you request the page. 在请求页面时会为您生成动态内容。 The document you view exists only for you at that moment; 您查看的文档仅在那时存在。 if viewed by someone else at the same time, or by you at a slightly different time, you could get something different. 如果同时有人查看您,或者您在稍微不同的时间查看,您可能会有所不同。
Dynamic content is good for: 动态内容有益于:

  • pages whose content changes too quickly to easily republish it 内容变化太快而无法轻松重新发布的页面
  • pages that display viewer-specific content (eg. user profiles) 显示查看者特定内容的页面(例如,用户个人资料)
  • pages that display content conditionally (ie. member-only pages) 有条件地显示内容的页面(即,仅会员页面)

However, dynamic content has the following disadvantages: 但是,动态内容具有以下缺点:

  • it is resource-intensive compared to static pages. 与静态页面相比,它占用大量资源。 That means the number of dynamic pages your server can display per second will generally be much less than the number of static pages. 这意味着服务器每秒可显示的动态页面数通常会比静态页面数少得多。 This can be especially important if you are swamped with traffic, or generating thousands of dynamic page views for robots or other automated agents that you don't really care about. 如果您挤满了流量,或者为您并不真正关心的机器人或其他自动化代理程序生成了数千个动态页面视图,那么这尤其重要。
  • dynamic pages execute code on your server, and can read from and write to your database. 动态页在您的服务器上执行代码,并且可以读取和写入数据库。 If your website has any security problems, dynamic pages is where those problems will be exposed. 如果您的网站有任何安全问题,动态页面将是暴露那些问题的地方。
  • in many typical default webserving configurations, the index page of a website is presumed to be a static page (eg. "index.html"). 在许多典型的默认Web服务配置中,假定网站的索引页面是静态页面(例如“ index.html”)。 That means there are some places where it is impractical or more difficult to use dynamic pages than others. 这意味着在某些地方使用动态页面比其他地方不切实际或更困难。

Is JavaScript code static or dynamic content? JavaScript代码是静态内容还是动态内容?

Yes the Javascript files residing on the server are considered to be static. 是的,驻留在服务器上的Javascript文件被认为是静态的。

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

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