mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Fix static assets cache logic (#5700)
This commit is contained in:
parent
511348974e
commit
cf22c55430
1 changed files with 12 additions and 9 deletions
|
@ -4,6 +4,7 @@ import base64
|
||||||
import binascii
|
import binascii
|
||||||
import codecs
|
import codecs
|
||||||
import collections
|
import collections
|
||||||
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import gzip
|
import gzip
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -1406,15 +1407,17 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||||
)
|
)
|
||||||
|
|
||||||
class StaticFileHandler(tornado.web.StaticFileHandler):
|
class StaticFileHandler(tornado.web.StaticFileHandler):
|
||||||
def set_extra_headers(self, path):
|
def get_cache_time(
|
||||||
if "favicon.ico" in path:
|
self, path: str, modified: datetime.datetime | None, mime_type: str
|
||||||
self.set_header("Cache-Control", "max-age=84600, public")
|
) -> int:
|
||||||
else:
|
"""Override to customize cache control behavior."""
|
||||||
if debug:
|
if debug:
|
||||||
self.set_header(
|
return 0
|
||||||
"Cache-Control",
|
# Assets that are hashed have ?hash= in the URL, all javascript
|
||||||
"no-store, no-cache, must-revalidate, max-age=0",
|
# filenames hashed so we can cache them for a long time
|
||||||
)
|
if "hash" in self.request.arguments or "/javascript" in mime_type:
|
||||||
|
return self.CACHE_MAX_AGE
|
||||||
|
return super().get_cache_time(path, modified, mime_type)
|
||||||
|
|
||||||
app_settings = {
|
app_settings = {
|
||||||
"debug": debug,
|
"debug": debug,
|
||||||
|
|
Loading…
Reference in a new issue