mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 12:55:46 +01:00
Fix static assets cache logic (#5700)
This commit is contained in:
parent
1bd2e558d6
commit
6c62c00963
@ -4,6 +4,7 @@ import base64
|
||||
import binascii
|
||||
import codecs
|
||||
import collections
|
||||
import datetime
|
||||
import functools
|
||||
import gzip
|
||||
import hashlib
|
||||
@ -1406,15 +1407,17 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||
)
|
||||
|
||||
class StaticFileHandler(tornado.web.StaticFileHandler):
|
||||
def set_extra_headers(self, path):
|
||||
if "favicon.ico" in path:
|
||||
self.set_header("Cache-Control", "max-age=84600, public")
|
||||
else:
|
||||
if debug:
|
||||
self.set_header(
|
||||
"Cache-Control",
|
||||
"no-store, no-cache, must-revalidate, max-age=0",
|
||||
)
|
||||
def get_cache_time(
|
||||
self, path: str, modified: datetime.datetime | None, mime_type: str
|
||||
) -> int:
|
||||
"""Override to customize cache control behavior."""
|
||||
if debug:
|
||||
return 0
|
||||
# Assets that are hashed have ?hash= in the URL, all javascript
|
||||
# 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 = {
|
||||
"debug": debug,
|
||||
|
Loading…
Reference in New Issue
Block a user