Page 1 of 1
serving css background images from CDN/Amazon cloud front
Posted: Mon Aug 20, 2012 8:46 am
by srini
I am trying to understand how I can serve css background images from Amazon S3/CDN. For product images,css & js files I am using cms:url tag but not sure what to do with images refered with in the css like background: #f2e8ce url("/broadleafdemo/images/containerTop.gif"). They are prefixed with app root url. Any guidence will be greately appreciated.
And also, what would be the best way for url rewrites (doing in app vs mod_jk or something like that). Currently I am getting something like localhost/myapp,localhost/myapp/store/gallery. I would like to show as localhost,localhost/gallery etc.
Thank you in advance,
Srini.
Re: serving css background images from CDN/Amazon cloud front
Posted: Thu Aug 23, 2012 4:31 pm
by aazzolini
Which version of Broadleaf are you on? Based on the usage of cms:url, I'm assuming that you are on a version prior to 2.0. If you are still starting out, we definitely recommend basing a project on Broadleaf 2.0.
Edit: A strategy I've used in the past to serve images from a CDN is to use mod_substitute in Apache HTTPD. Something like this:
Code: Select all
AddOutputFilterByType SUBSTITUTE text/html
AddOutputFilterByType SUBSTITUTE text/plain
AddOutputFilterByType SUBSTITUTE text/css
AddOutputFilterByType SUBSTITUTE application/javascript
Substitute "s|/images/|http://my.cdn.url/images/|niq"
When your application server responds with an html/plaintext/css/javascript file, mod_substitute will search for the string "/images" and replace it with the designated URL. That would then be sent to the client, who would fetch the image from the appropriate CDN instead.
Re: serving css background images from CDN/Amazon cloud front
Posted: Thu Aug 23, 2012 4:38 pm
by phillipuniverse
To your question about URL-rewriting, if you change the name of the built war to ROOT.war for Tomcat and root.war for Jetty, they will actually deploy your application to the / context rather than the /myapp context which is why you are getting those URLs.
Re: serving css background images from CDN/Amazon cloud front
Posted: Sun Aug 26, 2012 12:06 pm
by srini
Thank you Andre & Phillip.
I am wondering, in real time production environment, would changing the app name to ROOT.war best way?
Thanks,
Srini.
Re: serving css background images from CDN/Amazon cloud front
Posted: Sun Aug 26, 2012 4:46 pm
by phillipuniverse
I don't know of any issues with changing the app name to ROOT.war. This is normal practice for applications that you want at the root context of your servlet container.