rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
331 stars 105 forks source link

Feature request - Lazy load objectManager.js #368

Open jHabjanMXP opened 1 month ago

jHabjanMXP commented 1 month ago

Hey,

Is there an option to load objectManager.js only when it's needed?

    private readonly Lazy<Task<IJSObjectReference>> _structureModule = new Lazy<Task<IJSObjectReference>>(() => jsRuntime.InvokeAsync<IJSObjectReference>(
    "import", "./...etc...objectManager.js").AsTask());

...
var module = await _structureModule.Value;
await module.InvokeAsync(...
valentasm1 commented 1 month ago

Interesting. Could you show full sample? Also not sure if it is library resposinbility since this part is manual for anyone. Of course probable in latest blazor it is not de facto.

jHabjanMXP commented 1 month ago

I don't want to include js script in index.html as I'm using google maps only later in the app and I want my initial load time to be small - I don't want script evaluation to take CPU time.

https://stackoverflow.com/a/67536500/5909875

functions need to be exported for this module to use them though, And in order for module to access other javascript files, you need to import them directly in js file

jHabjanMXP commented 1 month ago

Created https://github.com/rungwiroon/BlazorGoogleMaps/pull/370

valentasm1 commented 1 month ago

Does it have any meaningful impact? Whats it the main motivation? Google maps Maps js are not loaded while you navigate to page

jHabjanMXP commented 1 month ago

Motivation - reduce initial load of js files (reduce network bandwidth and script evaluation)

valentasm1 commented 1 month ago

Do you metrics? I doubt that 40kb file has any impact. Maybe in other big libraries scenarios. Dont get me wrong i am not against it. Especially flexible implementation.