Git Product home page Git Product logo

20201110's Introduction

Usage of Assets w/i Micro Frontends

Deploying a Micro Frontend including referenced assets to a certain origin is challenging.

As long as the hosting HTML page is located in same path/origin, everything works as expected. This changes if one loads the Micro Frontend script bundle from a different origin.

As the HTML page defines the Base-HREF the Micro Frontend, which is deployed to a different origin, tries to find the assets referenced with a relative path at the host page's origin. This leads to errors loading the assets.

Possible solutions

There are possible solutions on how to fix this behavior:

Build-time

  • Base-HREF and Deploy-URL
  • Using absolute path definitions including origin
  • Inline assets by using a Base64 Data-URL

Post-build

  • Replacing path definitions with TypeScript- and CSS-variables

Deployment-time

  • Copy assets from Micro Frontend origin to host page origin

Runtime

  • Loading a CSS-file with relative path definitions directly in the hosting page
  • Assign Micro Frontend origin to the TypeScript- and CSS-variables

Server-side

  • Use a proxy configuration to serve the Micro Frontend's assets from the host's origin

Comparison

Shell with Micro Frontend Micro Frontend directly
Shell: partly loaded Micro Frontend: everything loaded

Errors on loading assets

  • Relative path in Angular Component's CSS file
  • Relative path in Angular's App CSS file, that is bundled to styles.ts
  • Relative path in Angular Template

20201110's People

Contributors

mikezks avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.