【发布时间】:2021-01-05 05:39:12
【问题描述】:
我想将 md5 哈希从 source.html 复制到另一个 docker 映像中的另一个静态文件以启用浏览器缓存,特别是如何在 bash 中将 /app.css 替换为 /app-67131f3c5c4e7877d424.css 和 /app.js 替换为 /app-67131f3c5c4e7877d424.js脚本是否整洁?
source.html
<!doctype html>
<html lang="en">
<head>
<link href="app-67131f3c5c4e7877d424.css" rel="stylesheet">
</head>
<body>
<script type="text/javascript" src="app-67131f3c5c4e7877d424.js"></script>
</body>
</html>
existing_file_as_target.html
<!doctype html>
<html lang="en">
<head>
<link href="/app.css" rel="stylesheet">
</head>
<body>
<script type="text/javascript" src="/app.js"></script>
</body>
</html>
请注意,这是简化版,我有很多脚本标签等。
现在我只是将app-67131f3c5c4e7877d424.css 复制到app.css,但这种方法会禁用浏览器缓存。
【问题讨论】:
-
你为这个任务做了什么?
-
我只是将带有摘要的文件复制到没有它的位置,因为使用 sed 我不知道如何将动态匹配重定向到适当位置的目标文件
-
你必须使用 html,xml 解析器来完成这项工作,也许你标记 bash、sed 或其他文本操作工具的 xmlstartlet 在特殊情况下可能会失败。