JSP/Spring MVC和CDN? [英] JSP/Spring MVC and CDN?

查看:118
本文介绍了JSP/Spring MVC和CDN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您建议采用哪种方法使您的JSP项目/Spring MVC项目准备好用于内容交付网络(CDN)?

Which approach do you recommend to make your JSP project / Spring MVC project ready for a Content Delivery Network (CDN)?

含义:在localhost上,静态内容应该是本地的,在实时网站上,静态内容应该由CDN传递.

Meaning: On localhost static contents should be local, on live website static contents should be delivered by CDN.

此刻,我仅看到以下选项:

At moment I see only following options:

  1. 使用环境属性,例如<img src="${env.resourceUrl}/mypath/pic.jpg" />
  2. 使用自定义标签<custom:img src="/mypath/pic.jpg" />,其中 按需附加CDN主机名
  3. 使用JQuery在客户端添加CDN主机名(不好的做法?),例如
    • $("img").each(function() { this.src = 'http://HOSTNAME/' + src; });
    • $("img").attr('src', function(index, attr) { this.attr = 'http://HOSTNAME/' + this.attr; });
  1. Use an environment property e.g. <img src="${env.resourceUrl}/mypath/pic.jpg" />
  2. Use an customized tag <custom:img src="/mypath/pic.jpg" /> which appends the CDN host name on demand
  3. Append CDN host name on client-side using JQuery (bad practice?) e.g.
    • $("img").each(function() { this.src = 'http://HOSTNAME/' + src; }); or
    • $("img").attr('src', function(index, attr) { this.attr = 'http://HOSTNAME/' + this.attr; });

有什么想法吗?欢迎所有建议:-)

Any ideas? All suggestions are welcome :-)

推荐答案

您可以使用属性"文件来管理URL和其他属性.在jsp中,您可以引用该文件中的属性.

You can manage your URLs and other properties using Properties file. In the jsp, you can refer the properties from that file.

基本上,您可以具有两个特定于您的环境的属性文件.当您在本地时,请使用本地属性文件,该文件将指向您的本地资源.如果您指向实时网站,请使用包含CDN网址的其他属性.在属性之间进行切换的工作是部署的一部分.

Basically you can have two properties files specific to your environment. When you are in local, use local properties file that will point to your local resources. If you point to live website, use the other properties that contains CDN urls. The effort to switch between properties is as part of your deployment.

这篇关于JSP/Spring MVC和CDN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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