Servlet,开发和用于静态文件的CDN [英] Servlets, development, and a CDN for static files

查看:130
本文介绍了Servlet,开发和用于静态文件的CDN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java网站(jQuery,Wicket,Maven,Spring,Hibernate),并且我们刚刚开始使用CDN在生产服务器上提供静态文件.我们将占位符用于CDN域,并将其添加到引用静态文件的每个静态文件中.通过使用Maven的属性过滤器,占位符将被Maven替换.

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.

因此,对于CDN提供的每个静态文件,我们都有这样的内容:

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

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

对于生产环境,$ {placeholder}被替换为" http://cdn.com ",对于开发环境,将其替换为空白.

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

...还有更好的方法吗?在静态文件本身中全局添加特定于Maven的占位符似乎很不寻常.也需要为以后的每个新映像添加该映像.另外,对静态文件的更改必须先通过Maven构建,然后这些更改才能在浏览器中显示,这会减慢某些环境中的开发速度.这可能是可以避免的,但起初似乎仍然是不必要的.

...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.

推荐答案

当我们以前做这种事情时,我们会将cdn url作为应用程序作用域spring bean公开的属性,然后可以注入该属性在applicationContext.xml中,这就是将其替换为maven过滤器的地方.然后,我们在jsps中引用具有该属性的EL表达式.

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.

这篇关于Servlet,开发和用于静态文件的CDN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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