简体   繁体   中英

Grails g:javascript tag with query string generates error

When I create a tag <g:javascript src="highcharts/highcharts.js?v=255" /> i get the error:

I can't work out the type of /tools/js/highcharts/highcharts.js?v=205 with type [text/javascript]. Please check the URL, resource definition or specify [type] attribute

The docs say that g:javascript doesn't have a type attribute and after looking through the grails source I found that it's using FileNameUtils.getExtension() to determine the type of resource. Since that just does a lastIndexOf('.') and returns the right side of that, it obviously won't be found. In this case we don't really need to add the v=255 so I can remove it for now however I'd still like to be able to do so in the future. What are my options here?

Grails version is 2.1.2

如何使用HTML标签?

<script src="highcharts/highcharts.js?v=255 type="text/javascript"/>

If all you want is deal with versioning javascript includes so you can set the cache high and change the number as needed you should look at the grails cached resources plugin .

Personally I think you would want to make highcharts.js part of a module for the resources plugin to deal with for you. It will take care of versioning and minification etc as you let it. The quick start should give you enough to get going.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM