-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Specify HTTP response headers for static assets #3126
Comments
Hi, me again :-) Any thought on if this is doable? I figured I'd ping and ask about it again before taking the plunge to work out an alternative solution that circumvents |
How are you including these JavaScript files in your app? All of your suggestions are reasonable ideas to explore, for sure, but there may be a way to help you avoid this without needing to change Shiny:
|
@gadenbuie thanks for the reply -- those are fair points. I'm a fan of the mydep <- htmlDependency(name = "foo", version = "abcdef0", src = ".", script = "myscript.js")
attachDependencies(tags$html(), mydep)
# Error: invalid version specification ‘abcdef0’ This error goes away when using something closer to a semver tag for Perhaps I should open an Issue about that in the {htmltools} repo and rethink this Issue based on what I learn over there. |
I can save you a little time to let you know that |
Thanks for that info. I do understand why that's done, but I also think it's a bit heavy-handed and believe:
Is there additional documentation anywhere on some of these details for the HTML dependency logic? mydep <- htmlDependency(name = "foo", version = "1.2.3", src = ".", script = "myscript.js")
attachDependencies(tags$html(), mydep) ... when inspecting the Shiny application I find the loaded resource will still ultimately use the 'raw' filename (e.g. "myscript.js" in the example). Sorry to dwell on this, if there's a Gist somewhere that I just haven't found, that'd be helpful (and/or I can just dig through the code when I have some free cycles for a better understanding). Either way, thanks for your continued work on Shiny -- it's great 😄! |
A core design goal of As a fundamental design goal, this behavior is well established and unlikely to change.
Browsers use the full path to the resource. By default the path includes the dependency version, so changing the version should change the path to the dependency, although there are options that control this behavior and that allow you to opt out of this. |
I've noticed that for some types of direct HTTP request handlers (e.g. to download data in an app), Shiny attaches a
cache-control
header to the response. In other cases, there's no such header attached, most notably in the case of serving static assets (like JavaScript files) via the canonicalwww
path or via paths added throughaddResourcePath()
.In some testing of an application of mine that requires JavaScript files to power parts of the front-end (FE), I've found that my browser(s) will at times cache the static assets, leading to out-of-sync FE and server-side Shiny code, typically breaking the application. Clearing cache fixes this, but asking my users to manage their local cache won't work too well :-).
I wonder if it'd be possible to register additional HTTP headers to be sent back with assets served via non-socket requests. One way to do this (that I can imagine) would be to register such headers at the
resourcePath
-level during the call toaddResourcePath()
. Then any file served through a matchingresourcePath
would inherit those headers and have them served up by Shiny on the response.This might be useful for lots of potential reasons, but my use case is very specifically for the
cache-control
header, and I'd generally be fine setting a pretty short TTL (e.g. 1 hour) for any file served by my application, and thus setting this as a 'global' Shinyoption()
would work, too.The text was updated successfully, but these errors were encountered: