Skip to content

Access to script root of a web part and dynamic loading of resources #2388

@wobba

Description

@wobba

Category

  • Question
  • Typo
  • Bug
  • Additional article idea

I wrote a post about loading resources from within the asset bundle (script, react components) only needed in edit mode at
https://www.techmikael.com/2018/08/an-adventure-into-optimizing-sharepoint.html

This could also be dynamic components loaded in any UI mode.

Right now we need to resort to custom gulp tasks to add files to be included into the .sppkg file, and getting the script URL where the bundle is served from is tricky. Pre v1.5 we could get it via context.manifests etc, but those properties have been «hidden» in v1.5. Which is why I decided to use a dummy image instead to go the supported route.

Ideally we would be able to reference scripts via the externals config section, and decide if the script is loaded automatically at runtime, or dynamically via SPComponentLoader. This would make it far easier to create runtime optimized web parts and extensions, loading and bootstrapping as little .js as possible per page, and load more as needed in the life cycle of the page. Having larger .js files loaded later is often more beneficial compared to loading large bundles up front.

I have employed this pattern to the modern script editor web part and to the react search refiner sample so far. Greatly reducing initial loading and bootstrapping.

Thoughts or comments around this?

Metadata

Metadata

Assignees

Labels

area:docsCategory: SharePoint developer/development documentation related

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions