Setup Preparation Connect Lifecycle Change Lifecycle Disconnect Lifecycle Reconnect Lifecycle Optimization
@porsche-design-system/components-js without any bundler, after loading the NPM package on any HTML page, looks like
this.<script>
porscheDesignSystem.load();
</script>
load() function loads the core chunk from the CDN. The core chunk can easily be identified in the
network tab of Chrome Developer Tools by its name containing the version number, e.g.
porsche-design-system.v3.8.0.688f651c1314ab84fa7b.js.customElements.define() is called for every component to register the custom html element in the browser (this is
how p-button tag to the DOM.<p-button>Hello</p-button>
:definedp-button:not(:defined) { visibility: hidden; }
hydratedp-button:not(.hydrated) { visibility: hidden; }
porsche-design-system.button.d471231621db4170e79a.js.Button class is created in the
JavaScript space.Important
constructor() the following lifecycle methods are executed in
order:connectedCallback()componentWillLoad()componentWillRender()render()componentDidRender()componentDidLoad()hyrated CSS class gets added to the component tag.<p-button class="hydrated">Hello</p-button>
@Watch('propName')componentShouldUpdate()componentWillUpdate()componentWillRender()render()componentDidRender()componentDidUpdate()p-button is removed from the DOM, only one lifecycle method of the class instance is invoked.disconnectedCallback()p-button element is added to the DOM again, just one lifecycle method is called.connectedCallback()const el = document.querySelector('p-button');
el.remove();
setTimeout(() => document.body.append(el), 1000);
p-button is added to the DOM, let's see how this
looks from the perspective of network requests and how to improve them if necessary.index.htmlindex.js of @porsche-design-system/components-jsregular and semi-bold weights are preloaded since they are most commonly used but this can be customized.font-family and that particular font-weight
which can lead to a phenomena called Flash of Unstyled Text (FOUT).getComponentChunkLinks({ components: ['button'] });
Hint
index.js file of
@porsche-design-system/components-js. That can be achieved by using the script with the code necessary to load the core chunk and it also takes care
of calling porscheDesignSystem.load() so that the manual part from the initial setup is superfluous.getLoaderScript().Hint
index.js would otherwise be bundled by
the JavaScript framework and you would end up shipping the same code twice, once bundled and once inlined in the
script tag.