“服务静态文件”究竟是什么意思? [英] What exactly does 'serving static files' mean?

查看:178
本文介绍了“服务静态文件”究竟是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在开发我的客户端应用程序,而不使用我自己的服务器在其后面运行,使用Webstorm的内置网络服务器来提供我的内容。

So far I've always been developing my clientside applications without any of my own servers running behind it, using Webstorm's built-in webserver to serve my content.

当人们使用Node with Express作为他们的网络服务器时,我经常看到的是关于你是否应该将你的html文件与节点或客户端代码放在一起的争论。

What I frequently see when people use Node with Express to act as their webserver is the debate on if you should put your html files with node or with the client code.

我理解html或css中包含的javascript文件最好存储在客户端目录中吗?

I understand javascript files that are included in html or css are best stored in the client directory?

所以我的第一个问题是,像这样的文件夹结构

So my first question is, with a folder structure like this

app/
  client/ js files
  server/ node files

您是否应在服务器或客户端目录中包含html页面?

Should you include your html pages in your server or your client directory?

其次:

有时我看到人们使用 express.static 静态文件,这里的静态文件究竟是什么?今天大多数网站不再是静态文档,而是通过操作DOM来改变javascript的文件,所以我认为任何html文件都不应被视为静态文件?

Sometimes I see people use express.static for static files, what exactly is implied by static files here? Today most websites are not static documents anymore but are files that get altered by javascript by manipulating the DOM, so I don't think any html files should be considered as static files?

据我所知,使用Node而不是内置web服务器的唯一优势是,如果我想拥有数据库访问权限。

As far as I can see, the only advantage I have with using Node instead of the built-in webserver is if I want to have database access.

推荐答案


今天大多数网站不再是静态文档,而是通过操纵DOM通过javascript改变的文件,所以我认为任何html文件都不应被视为静态文件?

Today most websites are not static documents anymore but are files that get altered by javascript by manipulating the DOM, so I don't think any html files should be considered as static files?

您网页的文件本身仍然是静态的。也就是说,您不是使用服务器端代码动态创建它们。在这种情况下,浏览器中发生的事情并不重要...这个想法是你不需要动态生成这些文件,因为它们的内容不会改变。

The files for your pages themselves are still static. That is, you are not creating them dynamically with server-side code. What happens in the browser doesn't matter in this context... the idea is that you do not need to generate these files on the fly, as their content does not change.


我理解html或css中包含的javascript文件最好存储在客户端目录中?

I understand javascript files that are included in html or css are best stored in the client directory?

将文件存储在服务器上的位置并不重要。重要的是您通常不希望从Node.js应用程序提供静态文件。像 express.static 这样的工具仅为方便起见。有时,您可能会使用低流量应用程序。在这些情况下,使用Node.js应用程序提供文件是完全可以接受的。对于具有良好流量负载的任何东西,最好将静态服务留给真实的Web服务器,如Nginx,因为这些服务器远比Node.js应用程序更有效。

Where you store your files on the server doesn't matter. What does matter is that you don't generally want to serve static files from your Node.js application. Tools like express.static are for convenience only. Sometimes, you may have a low traffic application. In these cases, it is perfectly acceptable to serve files with your Node.js app. For anything with a decent traffic load, it's best to leave static serving up to a real web server such as Nginx, since these servers are far more efficient than your Node.js application.

您应该在Node.js应用程序中保留您的应用程序代码(提供动态响应的代码,例如API服务器)。

You should keep your application code (code that serves dynamic responses, such as an API server) within your Node.js application.

这也是一个好主意把你的Node.js应用程序放在像Nginx这样的代理服务器上,这样代理就可以处理所有客户端交互(比如用勺子喂慢客户端),让你的Node.js应用程序做它最擅长的事情。但是,在低流量情况下,这无关紧要。

It's also a good idea to put your Node.js application behind a proxy like Nginx so that the proxy can handle all of the client interaction (such as spoon-feeding slow clients) leaving your Node.js application to do what it does best. Again though, in low traffic situations it doesn't matter.

这篇关于“服务静态文件”究竟是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆