File hash GET parameters for Django staticfiles
About
A class for the static files app in Django that invalidates outdated browser cache.
How to use
You add the line
A class for the static files app in Django that invalidates outdated browser cache.
How to use
You add the line
CODE:
STATICFILES_STORAGE = 'path.to.hashpathstaticfilesstorage.HashPathStaticFilesStorage'to your settings.py and everywhere you use the 'static' templatetag it will append a hash calculated form. the contents of the file as a GET parameter at the end of the URL for the file. Example:CODE:
{% static "path/to/file.txt" %} -> /static/path/to/file.txt?4e1243This guarantees that every time you update your static files, whether it is an image, a CSS file or anything else, all browsers fetch the new version of the file instead of using their cached versions.
Remember to change the import path to match your setup (replace the 'path.to' with your actual import path).
[b]Caching[/b]
You can reduce the time it takes to return the URL by caching the hashes when they are first calculated. The cache framework that ships with Django is used to store the hashes, so make sure you configure that before caching your hashes.
When you start using the cache, and every time after that when you have to invalidate the cache, you simply create an object of the type HashPathStaticFilesStorage and call the method 'invalidate_cache' on that object:
[code]
h = HashPathStaticFilesStorage()
h.invalidate_cache()
[/code]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-739707/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- file_get_content
- [20190522]How to get dump or list parameters set at session level.txtSession
- How to get the exact duration of an audio file in js All In OneJS
- WebLogic啟動報Could not get the server file lockWebServer
- file_get_contents傳送post請求
- PHP file_get_contents 與 curl 效能比較PHP
- 修復 Ubuntu 中 “E: The package cache file is corrupted, it has the wrong hash”UbuntuPackage
- TypeError: object() takes no parametersErrorObject
- .Net Core 中介軟體之靜態檔案(StaticFiles)
- c/c++語言函式 stat, fstat, lstat, fstatat - get file statusC++函式
- Visual C++ generate uuid via UuidCreate and CoCreateGuid,get time now,write string to fileC++GUI
- Android Audio HAL 介面介紹之 adev_set_parameters()和out_set_parameters()Androiddev
- 一文搞懂 $_POST 和 file_get_contents ("PHP://input") 的區別PHP
- curl的速度為什麼比file_get_contents快以及具體原因
- SAP Spartacus 中的 HTTP URL parametersHTTP
- file_get_content s()獲取https出現這個錯誤Unable to find the wrapperHTTPAPP
- hash
- Hash Map集合和Hash Set集合
- c++ 模板模板引數("Template Template Parameters")C++
- Dynamics CRM Xrm.Utility.openEntityForm passing lookup parametersORM
- hash hacker
- redis api hashRedisAPI
- location.hash
- Hash基本操作
- Hash——初識
- cat > file << EOF 與 cat > file << -
- java11新特性--Local-Variable Syntax for Lambda ParametersJava
- Pytorch:利用torch.nn.Modules.parameters修改模型引數PyTorch模型
- lombok get/set 與 JavaBean get/setLombokJavaBean
- File
- How to Convert Class File to Java File Online?Java
- redis - hash 實戰Redis
- Hash演算法演算法
- hash抓取總結
- HashMap、Hash Table、ConcurrentHashMapHashMap
- URL hash 屬性
- Python中hash加密Python加密
- Django(2) - Django模板Django
- URLSearchParams get()