{"id":8803,"date":"2025-04-21T22:25:54","date_gmt":"2025-04-21T16:55:54","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=8803"},"modified":"2025-04-21T22:25:58","modified_gmt":"2025-04-21T16:55:58","slug":"dynamic-import-in-javascript","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/dynamic-import-in-javascript\/","title":{"rendered":"Dynamic Import in JavaScript"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A feature that allows JavaScript modules to be loaded dynamically at runtime, instead of during initial page load is called dynamic import.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic loading generally improves performance by reducing initial bundle size and loading code only when needed (e.g., on user interaction). We use the import() function to load a module dynamically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an example to demonstrate the working of dynamic import in real time applications<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-14.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"466\" height=\"140\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-14.png\" alt=\"\" class=\"wp-image-8807\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-14.png 466w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-14-300x90.png 300w\" sizes=\"(max-width: 466px) 100vw, 466px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is a html file where a button click triggers the import of a module, demonstrating on-demand loading.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-12.png\"><img decoding=\"async\" width=\"630\" height=\"179\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-12.png\" alt=\"\" class=\"wp-image-8805\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-12.png 630w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-12-300x85.png 300w\" sizes=\"(max-width: 630px) 100vw, 630px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The result for the module will be functioned inside math.js which is dynamically called here and returned with the solution. &#8220;import&#8221; is used to include the math.js file dynamically inside this script.js file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-13.png\"><img decoding=\"async\" width=\"307\" height=\"76\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-13.png\" alt=\"\" class=\"wp-image-8806\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-13.png 307w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/04\/image-13-300x74.png 300w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Benefits of Dynamic Loading<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following are some of the key benefits of using dynamic loading in our applications using java script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Improved Performance<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reduced memory usage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Better user experience<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Modularity and maintainability<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bandwidth efficiency and enhanced security<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic loading is also called as lazy loading or on demand loading and is used in various contexts like operating systems, web development, game development, and mobile apps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A feature that allows JavaScript modules to be loaded dynamically at runtime, instead of during initial page load is called [&hellip;]<\/p>\n","protected":false},"author":503,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-8803","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2hZ","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/503"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8803"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8803\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}