-
-
Notifications
You must be signed in to change notification settings - Fork 902
Implement per-element and easily-customizable caching policy #5493
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
Draft
evnchn
wants to merge
6
commits into
zauberzeug:main
Choose a base branch
from
evnchn:caching-strategy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 tasks
This was referenced Nov 23, 2025
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 1, 2025
…ng) (#5497) ### Motivation While working on #5493 I also noticed that, full cached, NiceGUI documentation reaches out to: - `index.html` (obviously) - `codehilite.css` The latter we should be able to get rid of? ### Implementation - Filename may change so we do `${this.filename}` with the accompanying props. - Compute the file name and return the response using `_generate_codehilite_css()`, which is shared. - [ ] (Questionable) Apply `@lru_cache(maxsize=1)` to `_generate_codehilite_css()` because it doesn't ever change in runtime (an asusmption, is this right?) ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] Pytests have been added (or are not necessary). - [x] Documentation has been added (or is not necessary). ### Results Slow 4G no CPU throttling (because network is the bottleneck) Before: 1.46s load After: 1.00s load --------- Co-authored-by: Falko Schindler <[email protected]>
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 18, 2025
…nflicts (#5495) ### Motivation **TL-DR: `dependency.py` isn't coded as tightly as it should, silently letting (possibly critical) errors slide into client-side instead of stopping them right away and preventing the server from launching in a verbose and attention-grabbing manner.** I was working on #5493 and looking for space savings, when I found some interesting behaviour with regards to our dependency.py implementation. 1. We set key for `imports` at 2 places, libraries and ESM modules https://github.com/zauberzeug/nicegui/blob/eea9a48071f274657e65409571c255b9b35830e8/nicegui/dependencies.py#L180-L186 If ESM modules are to have the same name as a library, the library would be shadowed. 2. We append JS `import`s into `js_imports` at 2 places, one for `.js` components, one for `.vue` components https://github.com/zauberzeug/nicegui/blob/eea9a48071f274657e65409571c255b9b35830e8/nicegui/dependencies.py#L193-L207 This one is a bit more serious: If you run import twice with same name, browser JS errors out entirely, and the page grinds to a halt (white screen) `Uncaught SyntaxError: Identifier 'BLAH' has already been declared` ### Implementation - 2 sets: `import_names` and `component_names` - Do assertations before registration - Update the set before returning ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [ ] Pytests have been added (or are not necessary). - [x] Documentation has been added (or is not necessary). ### Final notes May break existing code which works (barely) in case 1, but I think we should break it, because the code isn't valid in the first place. --------- Co-authored-by: Falko Schindler <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature
Type/scope: New or intentionally changed behavior
in progress
Status: Someone is working on it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
NiceGUI can benefit from per-element caching to boost page load speeds on the second load afterwards, assuming element definitions remain constant.
There are previous attempts #4796 and #4900, which I will mainly compare the differences at the end.
Implementation
Python-land:
default_cache_keys, which is a list of nested keys..cache()to enable caching._to_dictexpects a hash from cookie (3), and:JS-land:
Progress
Past todo list entries:
Inherited from #4796
Cookies have 4KB size limits; could the hash data exceed this?Not in this PR since we use each cookie to store 1 elementsessionthen things break massively.Synchronous localStorage` operations might freeze UIIn short - just use it. It takes no time. 0.0007 of 1 millisecond.Comparison with past PRs
#4796
Boy is that an old PR. My coding style is much more drastic back then.
_to_dictentirely#4900
It's promising but several issues still:
isinstancechecks to restoreCachedStrclassknown_hashesof client, whereas this is done by the cookies in this PR.