自动插入 ETag(资产指纹)作为资源顶部的注释 [英] Automatically Insert ETag (asset fingerprinting) as comment at top of the resource

查看:19
本文介绍了自动插入 ETag(资产指纹)作为资源顶部的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 Play 在不使用第三方插件的情况下自动将文件的 ETag 作为注释插入文件顶部附近?

例如,对于 HTML 资源,在 标签的顶部插入 .>

关于如何使用 Play 框架的内置公共资产路由/指纹支持来做到这一点的答案也很棒.:)

相关问题:用于资产指纹识别的自定义 ETag 算法 &在 URL 中嵌入 ETag

解决方案

conf/routes 中添加以下内容:

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

app/controllers/Resources 控制器中:

包控制器导入 play.api.mvc._对象资源扩展控制器{def at(path: String): Action = {//计算ETagval etag = ETag(路径)//插入 ETag 的流文件好的(... <!-- ETag: etag --> ...)}}

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 <!-- ETag: 1234 --> at the top of the <head> tag.

Answers on how to do this with Play framework's built-in public assets routing/fingerprinting support would be great too. :)

Related questions: Custom ETag algorithm for asset fingerprinting & Embed ETag in URL

解决方案

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 --> ...)
  }
}

这篇关于自动插入 ETag(资产指纹)作为资源顶部的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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