grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 949 forks source link

Asset Pipeline does not generate ETags for files in src/main/webapp #9360

Closed daniellansun closed 9 years ago

daniellansun commented 9 years ago

Even when running under production mode, Grails 3.0.9 does not generate ETag for artefacts(e.g. js, css, image files) and make browsers cache them . BTW, Grails 2.5.1 can cache artefacts properly.

graemerocher commented 9 years ago

This has to do with asset pipeline I imagine. @davydotcom you seen this behaviour anywhere?

davydotcom commented 9 years ago

I have not, what version of asset pipeline is being used

graemerocher commented 9 years ago

3.0.9 uses 3.0.8 of the asset pipeline plugin

daniellansun commented 9 years ago

Thanks for your quick reply!

BTW Grails 3.0.8 can generate ETag for artefacts under "grails/assets" directory, but no ETag generated for artefacts under "src/main/webapp" directory.

graemerocher commented 9 years ago

Ah I see, that should be been put in the description then.

daniellansun commented 9 years ago

Hi Graeme,

 When I launch Grails app through "grails prod run-app" command, no ETags are generated for artefacts under "grails/assets" directory either. 
davydotcom commented 9 years ago

@danielsun1106 that is not the proper way to simulate a production run of grails. You must use the assembled fat jar container or war file to run in production mode properly. the asset-pipeline will still detect that the app is running in an unpackaged mode like this as run-app is solely used for development purposes.

davydotcom commented 9 years ago

Also this is correct src/main/webapp is considered a non asset-pipeline processed resource folder. I do not believe even grails 2.5.1 processes the web app folder either

daniellansun commented 9 years ago

Hi David, In the grails 2.5.1 project, the only directory to place js library(such as jquery-ui which contains js, css, images under single directory and not be classified as javascripts/stylesheets/images) is "web-app". It is true that artefacts can be cached properly.

 Could you tell me how to place js library such as jquery-ui under "grails/assets" in the Grails3? Thanks in advance.
davydotcom commented 9 years ago

This is not true. Remember all subfolders immediately under the assets folder are purely for organizational purpose. They do not specifically restrict the type of file to be placed in them. You can even create your own subdirectory within assets named however you see fit. For example, I often make a grails-app/assets/libs folder and store things like this in there.

daniellansun commented 9 years ago

@davydotcom Thanks for your sharing experience. When I make a grails-app/assets/libs folder and store things as you often do, how can I access these artefacts in the gsp page?

When I put images in the "assets/images", the images should be accessed by the following code:

<img src="${asset.assetPath(src: 'test.jpg')}" />

or

<asset:image src="test.jpg"/>

When I put images in the "assets/libs", how can I access these js, css and images files? Thanks in advance.

davydotcom commented 9 years ago

Just like you would an image. Lets say you put test.jpg in grails-app/assets/libs instead of images. The way you would reference that file is identical ` the first subdirectory level is essentially flattened and should be ignored for relative urls. Its like a merged filesystem,

daniellansun commented 9 years ago

It works! I'll migrate all my js lib to assets/libs. Thank you very much!

davydotcom commented 9 years ago

Id say we can close this ticket

graemerocher commented 9 years ago

Thanks @davydotcom