Automatically Insert ETag (asset fingerprinting) as comment at top of the resource

后端 未结 1 933
星月不相逢
星月不相逢 2021-01-26 05:21

How to ask Play to automatically insert the file\'s ETag as a comment near the top of the file without using third party plugins?

E.g., for a HTML resource, insert

相关标签:
1条回答
  • 2021-01-26 06:04

    In conf/routes add the following:

    GET  /resources/*file  controllers.Resources.at(file)
    

    In app/controllers/Resources controller:

    package controllers
    
    import play.api.mvc._
    
    object Resources extends Controller {
      def at(path: String): Action = {
        // calculate ETag
        val etag = ETag(path)
        // stream file with ETag inserted
        Ok(... <!-- ETag: etag --> ...)
      }
    }
    
    0 讨论(0)
提交回复
热议问题