DEV Community

Cover image for How I created in-memory DOM?
Abhishek Raj
Abhishek Raj

Posted on

5 2

How I created in-memory DOM?

Virtual DOM
Img Credits

Introduction

Few weeks back, I had a task to create an online code editor for HTML, CSS, JS and show the output on the same screen.

Why I needed in-memory DOM?

I stored different codes in different variables and for showing the output on same screen, I had to create a virtual DOM and merge all the codes (HTML + CSS + JS) together and inject it into an iframe.

Code

The above code takes HTML, CSS and Javascript as string and then combines them together in HTML. It returns the merged code as a string then it is injected into an iframe.

Demo

You can see the working of the above code in this app.
Web Code Editor

Edit 1.
Changed the title from VDOM to in-memory DOM, as I mistook it for a VDOM.
Thanks @lukeshiru for the suggestion.

Img Credits

  1. Crello
  2. Morioh

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (3)

Collapse
 
abhishekraj272 profile image
Abhishek Raj

Thanks for pointing out the bug. Will sort it out soon.

 
abhishekraj272 profile image
Abhishek Raj

Got it, will change the title.
Thanks for sharing.

Collapse
 
abhishekraj272 profile image
Abhishek Raj

Please do read this article.
reactkungfu.com/2015/10/the-differ...

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay