Grails Resources Plugin — How to get generated urls?

偶尔善良 提交于 2019-12-11 04:25:18

问题


Does anyone know how i could access the exact url that the resources plugin would spit out?

I want to use the resources plugin to optimize transfer of my javascript files, however, the application i'm writing is an html5 offline app that uses cache manifesting. Per the rules of cache manifesting, the cache manifest file must reference a file exactly as it appears in the html page.

The resources plugin adds a bunch of query string info and the checksum on an aggregated file . In order for resource plugin optimization and cache manifesting to work, I need to spit out the exact url that the resources plugin would in my cache manifest file.

Here's some examples of what I'm talking about:

The resources plugin will spit out the following in my html output:

<script src="/awesome-app/static/36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.js" type="text/javascript" ></script>

If i could get hold of the 36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.js part of the above url, I could include it in my cache manifest file like so:

CACHE MANIFEST

# rev 192

NETWORK:
*

CACHE:
static/36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.js  //<-- this would be the aggregated file!

Thanks for the help!


回答1:


I thought that renaming was part of the cached resources plugin and not the base resources plugin. If we're talking about the same thing, they're using SHA256 hash of each files byte contents to produce the hash. See the HashAndCacheResourceMapper and BASE62 classes on github and you'll see how they're generating the file names. Alternatively, if you're not relying on the caching mechanism from the plugin you can disable it and avoid the issue all together.



来源:https://stackoverflow.com/questions/11436495/grails-resources-plugin-how-to-get-generated-urls

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