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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hashControllerFilterMIT
- file_get_content
- unable to get file lock, will retry ...
- curl, fsockopen ,file_get_contents
- file_get_contents和fsockopen
- [20190522]How to get dump or list parameters set at session level.txtSession
- file_get_contents傳送post請求
- file_get_contents與curl的比較
- WebLogic啟動報Could not get the server file lockWebServer
- How to get the exact duration of an audio file in js All In OneJS
- JVM parametersJVM
- Django中的request.GET和request.POSTDjango
- 修復 Ubuntu 中 “E: The package cache file is corrupted, it has the wrong hash”UbuntuPackage
- v$nls_parameters和nls_database_parametersDatabase
- PHP file_get_contents 與 curl 效能比較PHP
- apt-get update更新源時,出現“Hash Sum mismatch”問題apt-get
- Oracle Parallel ParametersOracleParallel
- .Net Core 中介軟體之靜態檔案(StaticFiles)
- file_get_contents和fread的效能差別
- weblogic - <BEA-141281> <unable to get file lock, will retry ...>Web
- TypeError: object() takes no parametersErrorObject
- Oracle Hidden ParametersOracle
- Unix kernel parameters for OracleOracle
- 測評file_get_contents與curl 效率及穩定性
- file_get_contents與curl效率及穩定性問題
- c/c++語言函式 stat, fstat, lstat, fstatat - get file statusC++函式
- Understanding Initialization Parameters (85)
- Other SGA Initialization Parameters (96)
- Globalization Support Parameters in Views (178)View
- [PHP檔案管理器]⑤--file_get_contents檢視檔案PHP
- 解決PHP程序 CPU 100% -- file_get_contents惹的禍PHP
- file_get_contents 得到https型別url失敗的方法HTTP型別
- Weblogic BEA-141281 unable to get file lock, will retry 故障處理Web
- Oracle cascading standby ParametersOracle
- How to Change RabbitMQ Queue Parameters in Production?MQ
- 一文搞懂 $_POST 和 file_get_contents ("PHP://input") 的區別PHP
- hash
- curl的速度為什麼比file_get_contents快以及具體原因