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

Toolbar script loads external assets for all users #43

Open
skinread opened this issue Jan 2, 2019 · 6 comments
Open

Toolbar script loads external assets for all users #43

skinread opened this issue Jan 2, 2019 · 6 comments

Comments

@skinread
Copy link

skinread commented Jan 2, 2019

Loving Prismic, but when including the Toolbar script on a website, it would be great if the iframe and its external dependencies (bootstrap, jQuery) were only loaded when required for the current user.

I have a React/NextJS build and it looks like the iframe is injected and jQuery is loaded for every user even when not visible. It would be great if the Toolbar script could detect the cases where the user is logged in to Prismic or in a preview mode, A/B test, and inject only when needed/visible.

Would save about 30kb from what I can see.
Thanks

screen shot 2019-01-03 at 9 51 12 am

@angry-dan
Copy link

I'm also slightly concerned because the bootstrap file that is loaded isn't part of this repository (is it open source - I couldn't find it on github?) and it then goes on to load jQuery from a CDN.

From the minified source, I couldn't see much justification for jQuery's presence - a call to .ajax and .deferred. Maybe those could be replaced with modern equivalents of fetch and promise then the dependency could be removed entirely?

@alexmahan
Copy link

alexmahan commented Jun 25, 2019

I'm having the same issue. This affects the Lighthouse performance score for the page because the request to prismic.min.js is render-blocking.

The toolbar and its related files should only be loaded for users who are logged in and/or using the Preview or Edit features, not all users. I also agree that the jQuery dependency should be removed and replaced with more modern JS.

For the time being, I've worked around the performance issue by making the call to prismic.min.js async, and using preconnect for the other sources, but this feels a bit hacky:

<script src="//static.cdn.prismic.io/prismic.min.js" async>
<link rel="preconnect" href="https://code.jquery.com">
<link rel="preconnect" href="https://my-repo-name.prismic.io">

@simoncorompt
Copy link

Hi!

Any update on this?
I love the prismic toolbar but forcing it to load on all clients seems quite unoptimized.
As stated earlier, it affects Lighthouse audits quite a bit 😕

Maybe we could load a really small script first to check if user is logged on a prismic session (basically just a cookie check), and from there decide whether to load all the logic to handle previews / edit buttons?

@Martinhessmann
Copy link

Loading jQuery alone takes 1.22s seconds in our case. Our suggestion being loading the script with the defer attribute. ++

Bildschirmfoto 2020-07-06 um 12 25 46

@simoncorompt
Copy link

Using the defer attribute helps mitigate the problem, but it's not a solution in itself. We definitely should avoid loading external ressources on clients that don't need them at all, even if it doesn't block the loading of critical ressources.

For now we can probably do the cookie detection ourselves and append the script dynamically in the body (haven't tested this yet though), but it'd be nice if this was implemented directly in the toolbar script :)

@funkeeflow
Copy link

Push! Since it really is blocking us from using Prismic in our next projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants