Porsche Design System components load dynamically from a CDN as soon as they are used for the first time.
This results in a waterfall like loading behaviour where your application bootstraps first, then loads the Porsche
Design System Core and when any component rendered the corresponding component chunk gets loaded afterwards.
This can be optimized by fetching used chunks in parallel while the application is bootstrapping.
Therefore, we provide a ready to use partial in all @porsche-design-system/components-{js|angular|react|vue} packages
which needs to be injected into the <head> of your index.html.
Project integration differs based on the project setup.
The following showcases the most common ways.
Note: Make sure to preload only component chunks which are really needed initially!
prev
next
<!-- index.html -->
<head><!--PLACEHOLDER_COMPONENT_CHUNK_LINKS--></head>
<!-- package.json (tested on macOS, the script may need to be adjusted depending on the operating system used) -->
<!-- make sure to adjust the path to the index.html file -->
"scripts": {
"prestart": "yarn replace",
"replace": "placeholder='<!--PLACEHOLDER_COMPONENT_CHUNK_LINKS-->' && partial=$placeholder$(node -e 'console.log(require(\"@porsche-design-system/components-js/partials\").getComponentChunkLinks({ components: [\"button\", \"marque\"] }))') && regex=$placeholder'.*' && sed -i '' -E -e \"s^$regex^$partial^\" index.html" <!-- Alternative: force using China CDN -->
"replace": "placeholder='<!--PLACEHOLDER_COMPONENT_CHUNK_LINKS-->' && partial=$placeholder$(node -e 'console.log(require(\"@porsche-design-system/components-js/partials\").getComponentChunkLinks({ cdn: \"cn\" }))') && regex=$placeholder'.*' && sed -i '' -E -e \"s^$regex^$partial^\" index.html"}
Output
The result of this partial looks like this:
<link rel=preload href=https://cdn.ui.porsche.com/porsche-design-system/components/porsche-design-system.v3.28.0.bb0e1f205b7459f9181a.js as=script crossorigin>
<link rel=preload href=https://cdn.ui.porsche.com/porsche-design-system/components/porsche-design-system.button.2f58cffb4015198a0cc4.js as=script>
<link rel=preload href=https://cdn.ui.porsche.com/porsche-design-system/components/porsche-design-system.marque.5c679f961f2cbd8462b2.js as=script>
// Alternative: force using China CDN
<link rel=preload href=https://cdn.ui.porsche.cn/porsche-design-system/components/porsche-design-system.v3.28.0.bb0e1f205b7459f9181a.js as=script crossorigin>