Servlets, development, and a CDN for static files

我只是一个虾纸丫 提交于 2019-12-25 01:36:39

问题


I'm working on a Java site (jQuery, Wicket, Maven, Spring, Hibernate) and we have just started using a CDN to serve static files on our production server. We use a placeholder for the CDN domain, and have added it to every static file that references a static file. The placeholder gets replaced by Maven through properties filters with Maven.

So, for every static file served by the CDN, we have something like this:

<img src="${placeholder}/images/dogs/rex.jpg"/>

For production, ${placeholder} is replaced with "http://cdn.com" and for development environments, it is replaced with blank.

...Is there a better way? It seems unusual to globally add a Maven-specific placeholder to the static files themselves. It will need to be added for every new image going forward, as well. In addition, changes to static files MUST go through a Maven build before those changes will show in a browser, and this slows down development in certain environments. This is probably avoidable, but still seems unnecessary in the first place.


回答1:


When we used to do this kind of thing, we would have the cdn url be a property exposed by an application scoped spring bean, then you can inject this property in your applicationContext.xml and that's where you would replace it with the maven filter. Then we reference an EL expression with that property in the jsps.



来源:https://stackoverflow.com/questions/3197624/servlets-development-and-a-cdn-for-static-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!