Skip to content
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

Option for plugins to request that JSON be served on the page #1942

Open
simonw opened this issue Dec 10, 2022 · 3 comments
Open

Option for plugins to request that JSON be served on the page #1942

simonw opened this issue Dec 10, 2022 · 3 comments
Labels
javascript maybe-not-1.0 Things that might not need to block 1.0 after all plugins templates
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Dec 10, 2022

Idea came from a conversation with @hydrosquall - what if a Datasette plugin could say "I'd like the JSON for a page to be included in a variable on the HTML page"?

datasette-cluster-map already needs this - the first thing it does when the page loads is fetch() a JSON representation of that same data.

This idea fits with my overall goals to unify the JSON and HTML context too.

Refs:

@simonw
Copy link
Owner Author

simonw commented Dec 10, 2022

One way this could work: if plugins request it, a block like this is added to the page:

<script type="application/json+datasette" id="datasette-json">
{
  "...": "..."
}
</script>

Then a function could be provided which extracts and parses that data:

var data = await datasette.jsonData();

Why an await? Because then I could have it work the exact same way if the data is NOT available on the page - it could trigger a fetch() call for the same stuff. So loading it on the page becomes an optional performance optimization.

@simonw simonw added the maybe-not-1.0 Things that might not need to block 1.0 after all label Dec 11, 2023
@simonw
Copy link
Owner Author

simonw commented Dec 11, 2023

This is a micro-optimization that may not actually pay off, since it adds to the weight of the first page.

@hydrosquall
Copy link
Contributor

hydrosquall commented Dec 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript maybe-not-1.0 Things that might not need to block 1.0 after all plugins templates
Projects
None yet
Development

No branches or pull requests

2 participants