MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Host and Remote Container Configuration0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
16.1Micro-Frontend Architectures and Module Federation16.2Host and Remote Container Configuration16.3Cross-Application State Sharing and Event Buses
HomeTutorialsReact.js for AdvancedHost and Remote Container Configuration
Cross-Application State Sharing and Event Buses

Host and Remote Container Configuration

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

In enterprise micro-frontend deployments, hardcoding remote URLs into build configuration files (webpack.config.js) introduces deployment coupling: updating a remote's CDN endpoint requires rebuilding and redeploying the host application. Dynamic host and remote container configuration enables runtime remote resolution, version negotiation, and environment-driven URL injection.


1. Dynamic Remote URL Injection Pattern

Instead of static configuration strings, resolve remote containers at runtime using dynamic script injection:

1// src/utils/dynamicFederation.ts
2export async function loadRemoteComponent(
3 remoteUrl: string,
4 scope: string,
5 module: string
6) {
7 // 1. Check if remote script is already injected into DOM head
8 if (!(window as any)[scope]) {
9 await new Promise<void>((resolve, reject) => {
10 const script = document.createElement("script");
11 script.src = remoteUrl;
12 script.type = "text/javascript";
13 script.async = true;
14 
15 script.onload = () => resolve();
16 script.onerror = () => reject(new Error(`Failed to load remote script: ${remoteUrl}`));
17 
18 document.head.appendChild(script);
19 });
20 }
21 
22 // 2. Initialize the remote container's sharing scope
23 await __webpack_init_sharing__("default");
24 const container = (window as any)[scope];
25 await container.init(__webpack_share_scopes__.default);
26 
27 // 3. Obtain factory for requested component
28 const factory = await container.get(module);
29 return factory();
30}

2. Dynamic Remote Component Wrapper

1import React, { lazy, Suspense } from "react";
2import { loadRemoteComponent } from "./utils/dynamicFederation";
3 
4interface DynamicRemoteProps {
5 url: string;
6 scope: string;
7 module: string;
8 props?: Record<string, any>;
9}
10 
11export function DynamicRemote({ url, scope, module, props }: DynamicRemoteProps) {
12 // Lazily loads the remote component dynamically from provided URL
13 const Component = lazy(() => loadRemoteComponent(url, scope, module));
14 
15 return (
16 <Suspense
17 fallback={
18 <div className="p-4 bg-slate-800 text-slate-400 rounded text-xs animate-pulse">
19 Mounting remote container ({scope})...
20 </div>
21 }
22 >
23 <Component {...props} />
24 </Suspense>
25 );
26}

3. Environment-Aware Service Discovery

In production, fetch remote manifests dynamically from a centralized Service Discovery / Configuration service:

1import React, { useEffect, useState } from "react";
2import { DynamicRemote } from "./DynamicRemote";
3 
4interface RemoteManifest {
5 analytics: string;
6 billing: string;
7 support: string;
8}
9 
10export function EnterprisePortal() {
11 const [manifest, setManifest] = useState<RemoteManifest | null>(null);
12 
13 useEffect(() => {
14 // Query runtime discovery endpoint for active remote CDN versions
15 fetch("/api/v1/config/microfrontends")
16 .then((res) => res.json())
17 .then((data: RemoteManifest) => setManifest(data));
18 }, []);
19 
20 if (!manifest) return <div>Resolving service discovery...</div>;
21 
22 return (
23 <div className="p-8 space-y-6 bg-slate-950 text-white min-h-screen">
24 <h1 className="text-xl font-bold">Dynamic Enterprise Micro-Frontend Portal</h1>
25 
26 {/* Renders billing remote resolved at runtime */}
27 <DynamicRemote
28 url={manifest.billing}
29 scope="billing_remote"
30 module="./BillingSummary"
31 />
32 
33 {/* Renders analytics remote resolved at runtime */}
34 <DynamicRemote
35 url={manifest.analytics}
36 scope="analytics_remote"
37 module="./ExecutiveCharts"
38 />
39 </div>
40 );
41}

4. Shared Dependency Version Negotiation

When Host and Remote applications specify different versions of a shared package in their package.json, Module Federation applies SemVer rules:

  • If versions are compatible (e.g. Host requires ^18.2.0, Remote requires ^18.1.0), Webpack loads the highest compatible version.
  • If singleton: true is set and versions conflict incompatibly (e.g. 17.0.0 vs 18.2.0), Webpack logs a console warning and uses the host's version, preventing multiple conflicting runtimes.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is static remote URL configuration in webpack.config.js limiting in enterprise multi-cloud environments?
Question 2
What are __webpack_init_sharing__ and __webpack_share_scopes__ in Module Federation?
Question 3
How does a dynamic remote component handle a runtime network failure when loading remoteEntry.js?
Question 4
What role does a "Service Discovery" configuration endpoint play in micro-frontend architectures?
Question 5
What happens if a shared dependency has singleton: true and strictVersion: true and the versions do not match?
Next Lesson

Cross-Application State Sharing and Event Buses

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Micro-Frontend Architectures and Module FederationCross-Application State Sharing and Event Buses

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext