简体   繁体   English

哈希文件用于静态内容Web服务器

[英]Hash files serve static content web server

I am writting my own static web content delivery routines. 我正在编写自己的静态Web内容传递例程。 For caching I plan to include hashes in URLs like 对于缓存,我计划在类似URL的URL中包含哈希

/static/file.MD5HASH.png /static/file.MD5HASH.png

I am developing in a static, compiled language. 我正在使用静态的编译语言进行开发。 I read https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#cachedstaticfilesstorage and https://gist.github.com/3207357 我阅读了https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#cachedstaticfilesstoragehttps://gist.github.com/3207357

Now my mental problem is how to determine efficiently the hash of a file? 现在我的精神问题是如何有效地确定文件的哈希值? I will not calculate the hash upon every request to the server. 我不会根据对服务器的每个请求来计算哈希。 So I need some caching. 所以我需要一些缓存。

I could write a helping program which takes the path to the static content, recursively calculates the hash and stores the result as 我可以编写一个帮助程序,该程序采用静态内容的路径,递归地计算哈希并将结果存储为

filename.png HASH filename.png哈希

in a file called .cache.hash.lookup. 在名为.cache.hash.lookup的文件中。 This file is loaded on web server start and statet on every request so when a static file is about to be served it will look it up in the cache and if the cache is outdated, re-load the cache. 该文件在Web服务器启动时加载,并在每次请求时声明,因此当要提供静态文件时,它将在缓存中查找该文件,如果缓存已过期,请重新加载缓存。

Is this feasible? 这可行吗? Please I do not need advice how to do it using framework X as I would like to understand it and write my own routines. 请不要建议我如何使用框架X进行操作,因为我想了解它并编写自己的例程。

Reading your link, the idea there is to store multiple versions of the same resource, so adding the hash to the filename happens when you insert a new file. 阅读您的链接后,这里的想法是存储同一资源的多个版本,因此在插入新文件时会在文件名中添加哈希。

Your HTTP server can be dumb and just look up files by name. 您的HTTP服务器可能很笨,只能按名称查找文件。 (another advantage I see is you can blindly respond with "304 Not changed" to any conditional request, as the hash in the filename acts as the etag.) (我看到的另一个优点是,您可以对任何条件请求进行盲目响应,“ 304不变”,因为文件名中的哈希充当etag。)

Or am I missing something? 还是我错过了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从内部服务器提供Java Web应用程序中的静态内容? - How to serve static content in a Java web app from internal server? cherrypy-提供静态文件并强制内容类型 - cherrypy - serve static files and force content-type 404 GET(尝试使用Tornado Server提供静态文件): - 404 GET (Trying to use Tornado Server to serve static files): 如何提供文件下载服务? 尝试为用户提供文件以供查看/下载,但服务器以错误的Content-Type响应 - How to serve files for download? Trying to serve files for users to view/download, but server responds with wrong Content-Type 如何使用 serve-static 提供多个文件? - How to serve multiple files with serve-static? 在root上提供静态内容,在/ api上提供静态内容 - Serve static content on root and rest on /api web.py可以使用内置服务器路由静态内容吗? - Can web.py route static content with its builtin server? Golang从内存中提供静态文件 - Golang serve static files from memory 服务多个 static 文件并在 golang 中发出 post 请求 - Serve multiple static files and make a post request in golang 如何使用dropwizard为每个网址提供多个静态文件? - How to serve multiple static files using dropwizard for each url?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM