Angular and Domino: A Powerful Combo for Server-Side Rendering.

Angular and Domino: A Powerful Combo for Server-Side Rendering.

How to Use the DOM with Server-Side Rendering

Table of contents

No heading

No headings in the article.

If you are using Angular and need to access DOM with SSR, then use the domino package.

Domino provides support for the DOM API and also CSS for querySelector(), querySelectorAll(), and matches().

Install the domino package from your terminal.

npm install domino --save

Add angular universal in your app. ng add @nguniversal/express-engine Edit the server.ts file and add the following lines. To configure it, create a "document" object and a "window" as global.

const domino = require('domino');
const fs = require('fs');
const path = require('path');

// Use the browser index.html as a template for the mock window
const template = fs
  .readFileSync(path.join(join(process.cwd(), 'dist/yourprojectname/browser'), 'index.html'))
  .toString();

// Shim for the global window and document objects.
const window = domino.createWindow(template);
global['window'] = window;
global['document'] = window.document;

If you want to copy and paste, please change the project name.

Keep in mind that change for server-side render, the build command is built:ssr and needs to publish the browser directory.

npm run build:ssr
dist/yourprojectname/browser