4

Which approach do you recommend to make your JSP project / Spring MVC project ready for a Content Delivery Network (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. 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 :-)

pitschr
  • 529
  • 1
  • 6
  • 13

1 Answers1

2

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

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.