-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decouple cache buster from top-level asset spec #2145
Comments
I was going to work on this over the weekend, but I am stuck on number 1 that you've listed. Do we go in reverse order of registration, so that later cache busters override earlier ones? The cache buster doesn't really know for what path it was registered and whether it originally "busted" the URL or not. |
Yeah later defs should override newer ones but two cache busters with the same path should conflict. Ideally also if you define a buster on a specific subpath/file and then add a newer buster covering a superset of those paths it should also conflict. That's not directly covered by the conflict api though so it would need to be done manually in the action. |
I was planning on working on this, but then spent the next two hours thinking about it before hitting up @mmerickel on IRC and coming to the following list of issues:
[1]: Single file override already works as is, it is adding the cachebusting that is an issue. |
After talking to @dstufft in IRC I think we came to a conclusion that should work well. We can simply remove the
|
@mmerickel Ok. |
Progress update: import os.path
import posixpath
from pyramid.config import Configurator
here = os.path.dirname(os.path.abspath(__file__))
def cachebust(token):
def cachebust(spec, subpath, kw):
print('spec=%s' % (spec,))
print('subpath=%s' % (subpath,))
fname, ext = posixpath.splitext(subpath)
return fname + token + ext, kw
return cachebust
def main(global_config, **app_settings):
config = Configurator()
config.add_static_view('static', 'myapp:static')
config.override_asset('myapp:static/theme/', here)
config.override_asset('myapp:static/a.png', 'theme:static/a-override.png')
config.override_asset('myapp:static/c.png', 'theme:static/c-override.png')
config.add_cache_buster('theme:static', cachebust('-1111'))
config.add_cache_buster(here, cachebust('-2222'))
config.add_cache_buster('myapp:static', cachebust('-3333'))
config.add_view(some_view)
return config.make_wsgi_app()
def some_view(request):
print(request.static_url('myapp:static/a.png'))
print(request.static_url('myapp:static/images/b.png'))
print(request.static_url('myapp:static/theme/c.png'))
print(request.static_url('myapp:static/d.png'))
return request.response
if __name__ == '__main__':
from waitress import serve
app = main({})
serve(app, host='127.0.0.1', port=8080)
|
Supporting absolute path overrides is a little bit of a quirk. I'm going back and forth right now but I think I will need to require a trailing / when adding a cache buster for a folder in order to avoid applying a cache buster registered for |
Currently the cache buster api is coupled to the asset spec defined in
config.add_static_view('myapp:static', '/static', cachebust=CacheBuster())
. This does not play well withconfig.override_assets(to_override='myapp:static/theme/', override_with='mytheme:static/')
(a desirable pattern for static views). The issue is that some assets are pulled in from other packages which are not atmyapp:static
and thus cannot be properly cache busted without knowing what is overridden and what is not.ICacheBuster
interface receives no information about the fact that this asset is overridden. The spec it received ismyapp:static
, nevermytheme:static
.This should be decoupled such that raw paths can be busted. I'm proposing
config.add_cache_buster('mytheme:static/', cache_buster, cache_max_age)
.Two problems with this API that we'll need to solve:
add_cache_buster
which cache buster is used on the matching side when a URL comes into the system?ICacheBuster.pregenerate
to return some info about whether it is busted? Check whether the parameters are mutated?ping @bertjwregeer, @dstufft
The text was updated successfully, but these errors were encountered: