Grails资源插件 - 如何获得生成的网址? [英] Grails Resources Plugin -- How to get generated urls?

查看:85
本文介绍了Grails资源插件 - 如何获得生成的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用资源插件来优化我的JavaScript文件的传输但是,我正在编写的应用程序是一个使用缓存清单的html5离线应用程序。根据高速缓存清单的规则,高速缓存清单文件必须完全按照html页面中显示的文件引用文件。

资源插件在聚合文件中添加了一堆查询字符串信息和校验和。为了让资源插件优化缓存显示工作,我需要提供资源插件在我的缓存清单文件中的确切网址。



以下是我正在谈论的一些示例:



资源插件将在我的html输出中显示以下内容:

 < script src =/ awesome-app / static / 36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.jstype =text / javascript>< / script> 

如果我能得到 36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.js 上面url的一部分,我可以将它包含在缓存清单文件中,如下所示:

  CACHE MANIFEST 

#rev 192

网络:
*

CACHE:
static / 36wl8Nwm8L7ZZMSbV6NVQPfi6xCx6DcVV0wFDCYRyv5.js //< - 这将是汇总的文件!

感谢您的帮助!

解决方案

我认为重命名是缓存资源插件的一部分,而不是基本资源插件。如果我们谈论的是同样的事情,他们使用每个文件字节内容的SHA256散列来产生散列。请参阅 HashAndCacheResourceMapper BASE62 类,你会看到它们是如何产生文件名的。或者,如果您不依赖插件中的缓存机制,则可以禁用它并避免所有问题。


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!

解决方案

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.

这篇关于Grails资源插件 - 如何获得生成的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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