问题描述
我的网站中(流量高)部分是完全静态的.该网站的所有URL都是相对的,因此,如果我只是将浏览器指向http://gj232j2j213.cloudfront.net/blah
,那么所有这些URL都可以正常工作.
I have a (high-traffic) chunk of my website that is entirely static. All the site's URLs are relative, so right now it all works if I just point my browser to http://gj232j2j213.cloudfront.net/blah
.
我想将整个内容(不仅是图像和CSS,还包括HTML)托管在Cloudfont(或其他CDN)上.
I'd like to host the entire thing (not just images and css, but the HTML too) on Cloudfont (or some other CDN).
理想情况下,我可以输入以下内容:
Ideally, I could put something like:
GET /static/ staticDir:http://gj232j2j213.cloudfront.net/blah
在我的路线文件中.这样,我的URL看起来就像www.mydomain.com/static/main.html
,当用户在我的静态URL和非静态URL之间来回移动时,我不必将用户跳到另一个子域.
in my routes file. That way my URLs would look like www.mydomain.com/static/main.html
, and I wouldn't have to bounce the user to a different subdomain as they moved back and forth between my static and non-static URLs.
有什么想法吗?我被误导了吗?
Any ideas? Am I misguided?
推荐答案
我在我的conf/routes
文件中使用了以下内容:
I've used the following in my conf/routes
file to do this:
# Map static resources from the /app/public folder to the /public path
#{if play.Play.mode.isDev()}
GET /public/ staticDir:public
#{/}
#{else}
GET d2iu8jbjgczc8x.cloudfront.net/public staticDir:public
GET /public/ staticDir:public
#{/}
然后,您仅以常规方式引用静态资产,URL将使用CloudFront服务器(处于Prod模式).
Then you just reference the static assets the normal way and the URLs will use the CloudFront server (in Prod mode).
这篇关于在Play中托管静态HTML! CloudFront上的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!