-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow django_css
and django_js
to load only_once
#194
Comments
Note to self: Storing the stylesheet within the scope will still result in duplicate stylesheets if multiple root components exist on the page. Loading the stylesheets might need to be handled via JavaScript and somehow globally track whether a stylesheet is needed. Or thinking in reverse, perhaps we should always load the stylesheet every time, but have duplicates get deleted via JavaScript? Another idea is using a global JavaScript object to keep track of how many components want a certain stylesheet. The stylesheet themselves would need to be stored in some master object, and would need to get unloaded after there are no component left that use the stylesheet. On the page, this master object might look like this: <body>
<div id="reactpy-stylesheets">
<style id="path/to/stylesheet.css"> ... </style>
</div>
</body> |
Closing due to reasons described here: |
Current Situation
Currently, a user can add
django_css
to the body of a component that is rendered multiple times. This means that the CSS stylesheet will be duplicated for each component that is on the page.Proposed Actions
Add an
only_once = True
argument todjango_css
anddjango_js
. This will prevent CSS/JS duplication if the static file has already been loaded within the current component tree.To detect whether a static file has been loaded, we should store whether a
static_file_path
has already been loaded within the ASGIscope
. Here's some pseudocode on the concept:The text was updated successfully, but these errors were encountered: