benhoIIand / grunt-cache-bust

Cache bust static assets using content hashing
MIT License
265 stars 103 forks source link

How to make work with JSP EL expression #167

Closed spshukla closed 8 years ago

spshukla commented 9 years ago

We are hosting our static resources over CDN, so all our static resources URL get prefixed by CDN url.

We are using JSP, so our static resources like

Obviously, cache burst wont be able to resolve the JSP EL. So, how do I configure cache burst to burst these resources.

benhoIIand commented 8 years ago

Hi @spshukla,

Was there meant to be a code example in this issue? Sounds like an easy thing to fix, just need to see an example

spshukla commented 8 years ago

We map our static assets to CDN (Cloudfront) url, so in our JSPs any static resource is represented like this

Hi @hollandben

<img src="${cdn_url_path}/test/images/abc.jpg"/>

Lets suppose ${cdn_url_path}=http://cdnurl.aws.com

This CDN url is mapped to our LB IP, that LB in turn sends the request to our application web servers.

So, while using your plugin this JSP EL expression needs to be mapped with our context root folder, so that those files could be found and perform cache bursting accordingly.

Please let me know for any more info.

benhoIIand commented 8 years ago

Ahh ok. You could probably get away with setting the cdnPath option to be the literal string ${cdn_url_path}. Don't see why that shouldn't work.

spshukla commented 8 years ago

@hollandben

Please find the logs and verify the configuration.

Inside "web" folder contains all the JSPs, CSS in folders (project wise)

Got error message like this whilc running grunt task

Static asset "web/${static_file_path}/common/css/commonHeader_SS_L_7.css" skipped because it wasn't found, original reference=$%7Bstatic_file_path%7D/common/css/commonHeader_SS_L_7.css

Confguration in Grunt JS:--

cacheBust: {
    options: {
      encoding: 'utf8',
      algorithm: 'md5',
      length: 16,
      jsonOutput: true,
      cdnPath: '${static_file_path}'
    },
    assets: {
        files: [{
                baseDir : 'web/',
                src: ['web/**/*.*']
        }]
    }
  }
spshukla commented 8 years ago

@hollandben Please help with this.

benhoIIand commented 8 years ago

I've had deeper look into the code and the original suggestion unfortunately won't work. The other option I can see will be to use the replaceTerms option, but that will actually replace ${cdn_url_path} in the HTML file with the path that you give it. You could read the config file where that value is stored into your Gruntfile so you wouldn't need to change it in more than one place.

benhoIIand commented 8 years ago

Appears the be the resolution as #161 - should work in 1.x.x