为什么在 Rails 目录结构中样式表和脚本与应用程序分开
我一直不明白为什么样式表和脚本位于 ruby on Rails 中的 /app
文件夹之外。将它们存放在远离 /app
的 /public
文件夹中是否有好处?
感谢! 马特
I never understood why the stylesheets and scripts are outside the /app
folder in ruby on rails. Is there benefits of housing them in the /public
folder away from the /app
?
Thank!
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在生产环境中,
/app
由 Ruby 应用服务器提供服务,即 mongrel、thin、unicorn 等,而/public
由网络服务器提供服务更好地提供静态内容,即 nginx。有时您还希望将/public
解耦,由 CDN,即 Amazon S3。将这两个目录解耦可以在生产环境中提供更好的部署安排。In production environment,
/app
is served by Ruby appserver, i.e mongrel, thin, unicorn, etc, while/public
is served by a webserver that is better in serving static content, i.e nginx. Sometimes you would also want to decouple/public
to be served by a CDN, i.e Amazon S3. Decoupling this two directory provides better deployment arrangement in production environment./app
文件夹通常包含动态 数据,/public
文件夹包含静态 文件。这是为了缓存和性能而设计的。 Web 服务器可以将/public
文件夹中的文件直接输出给用户,而无需额外的 Ruby 调用。它还可以缓存静态文件,为其设置各种标头等等。The
/app
folder usually contains dynamic data, the/public
folder contains static files. This was made for caching and performance. A Web-server can output files in the/public
folder directly to the user, without additional Ruby calls. It also can cache static files, set various headers on them and so on.