3

I was currently facing an issue during the initial loading time. I wanted to reduce it as much as possible. To achieve this, I implemented deferred loading and minimized the initial calls that I was using in the index.html file. I utilized callback listeners and invoked them from the Flutter web Dart calls when needed. This approach helped us reduce the loading time during the initial phase.

Call back listeners in index.html file

 <script> function loadStripeScript() { const script = document.createElement('script'); script.src = 'https://js.stripe.com/v3/'; script.defer = true; document.head.appendChild(script); } function loadGoogleMapsApi() { const script = document.createElement('script'); script.src = 'https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR KEY'; script.async = true; script.defer = true; document.head.appendChild(script); } </script> 

Invoke from the Dart file

import 'dart:js' as js; //Load js scripts functions Future loadGooglePlacesWithDelay() async { await js.context.callMethod('loadGoogleMapsApi'); } 
4
  • On one side, this is interesting. at the same time, I don't understand what is exactly your question. Why do you need delayed imports? What's the point here? Do you want to load the scripts in a predefined order, or wait for some to finish loading until you get the next one? Or would you prefer to have them stored in memory and load them as needed? There are many options. I think you should rephrase your question. Commented Sep 18, 2023 at 15:35
  • 1
    @Caniho, it's a solution, not a question. I have posted this to help others because I have spent a lot of time optimizing Flutter web to reduce the initial loading time. During this time, I realized that some of the HTML imports take several seconds to load, such as Pusher, Stripe, and other plugin imports. These imports can be appended after the app loads. This approach can greatly help us reduce the initial loading time for Flutter web environments. Commented Sep 21, 2023 at 6:16
  • Don't get me wrong, I really enjoy learning about this and appreciate your effort. But you shouldn't open questions as a solution on Stack Overflow. Eventually, it will be flagged. Anyway, I upvoted because I feel there's some value in this. Commented Sep 21, 2023 at 14:06
  • @Canilho Thanks Commented Sep 26, 2023 at 12:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.