How do I reference assets from a different subdomain (or CDN) in production?

I am working both in the Ruby and Java worlds. I have been inspired somewhat by the merb-assets project, which provides various functionality to make it easy to reference assets (images, CSS, etc.) located on a subdomain (or CDN).

I want to do the same in Java:

  • in development and testing, I want to use either JSTL's <c:url> or Struts 2's <s:url value=""/> tags to reference assets.
  • but in production, I want to move most of these assets out to a separate subdomain (or CDN).

Are there any taglibs (or other methodologies) out there that can help with this? I don't particular want to litter my views with <c:if and tests for localhost, everytime I insert an <img> or <link> tag.

I am using Struts 2 + JSP.


Asked by: Brianna776 | Posted: 23-01-2022






Answer 1

I don't really know Struts 2, but I am thinking of a solution that involves the use of Maven2 features... So, in the case you are indeed using Maven2 to build your application, you may solve your problem with the resources filter and profiles features.

Resources filtering: You can ask Maven2 to filter ressources files (in our case, the JSP files). Filter means to replace all ${xxx} by their value. This will be useful to replace a parameter (${domain.url} for example) by the value you need to have ("localhost", "http://...").

Then, you define 2 profiles: "development-test" and "production". Each profile will define its own domain for these assets. For example, in development-test, you can define the domain as "localhost", in production, the domain will be "http://....".

I am not sure if this can solve your problem, but you can give it a try :o)

References : Filter resources: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html Profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Answered by: Blake711 | Posted: 24-02-2022



Similar questions

java - Is a good idea to enable jmx (lambda probe) on a production server?

We are experiencing some slowdowns on our web-app deployed on a Tomcat 5.5.17 running on a Sun VM 1.5.0_06-b05 and our hosting company doesn't gives enough data to find the problem. We are considering installing lambda probe on the production server but it requires to enable JMX (com.sun.management.jmxremote) in order to obtain memory and CPU statistics....


java - Analyze Tomcat Heap in detail on a production System

Having analyzed a light-load web application running in tomcat, using JMX Console, it turns out the "PS Old Gen" is growing slowly but constant. It starts with 200MB and grows around 80MB/Hour. CPU is not an issue, it runs at 0-1% on average, but somewhere it leaks memory, so it will become unstable some days after deployment. How do i find out what objects are allocated on the heap? Are there any good tuto...


java - AspectJ load-time weaving in production systems

Does anyone have an experience with pure AspectJ load time weaving in production systems (mostly interesting Tomcat related activities)? I'm slightly worrying regarding memory footprint and cpu overhead.


java - Joone vs. Encog - production apps

Has anyone used both Joone and Encog in production applications? Is there something you needed to do in a production app with one or the other where the product fell short?


java - Secure Debugging for Production JVMs

We have some applications that sometimes get into a bad state, but only in production (of course!). While taking a heap dump can help to gather state information, it's often easier to use a remote debugger. Setting this up is easy -- one need only add this to his command line: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=PORT There seems to be no available security mechanism, so turnin...


java - How to mark some code that must be removed before production?

Sometimes for testing/developing purposes we make some changes in the code that must be removed in a production build. I wonder if there is an easy way of marking such blocks so that production build would fail as long as they are present or at least it will warn you during the build somehow. Simple "//TODO:" doesn't really work because it is ofter forgotten and mixed with tons of other todos. Is there...


Should Java programs compiled with debugging information not be used in a production system?

Is there any reason I should avoid compiling in debugging information with Javac in my Java classes for use in a production server? Are there any speed or security concerns I should be aware of? Please note that I am referring to debugging information like line numbers in stack traces, not the debug level of loggers. Related Question:


Need Java https proxy which can be enhanced to emulate production https proxy behaviour

I have a production environment which require access through a proxy server. Occasionally said server returns blank responses badly confusing the Metro web service library causing all kinds of interesting RuntimeExceptions. I believe the proxy is Squid. In order to handle these better, I would like to set up a similar scenario here with a local proxy under my control causing all kinds of interesting failures. A ...


java - Is this safe on a production server?

I have a database application (or search engine) which is called Solr. I connect to it via port 8983. I do this from PHP code, so I add and remove records from it via php. On my server I have a firewall. I have set this firewall to only allow connections to and from this port (8983) from the ip address of my own server. In other words, only allow servers IP to access this port. Is th...


java - Tomcat in Production

Closed. This question does not meet Stack Overflow guid...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top