Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:17:52+00:00 2026-06-07T16:17:52+00:00

Say, I’ve got an HTML file that I want to process using Javascript. For

  • 0

Say, I’ve got an HTML file that I want to process using Javascript. For example:

  • Add some DOM elements, like span or div wrappers.
  • Change the document styling a bit, like base font size, line-height, etc.
  • Use a hyphentor to add ­ entities.

What would be the most efficient way to do this, i.e. I’d like to do it with a minimum amount of reflows.

The ideal case would be having the JS-code run before even the first layout. Is this possible? I know, it’s generally a bad idea to execute expensive scripts before the page has been displayed for this would make the page look blank for some time and it’s a really bad experience. However, I’m going to need this to work offline and this would not be an issue for my project.

Or, is there’s a way to do all the dom modifications in one bunch, i.e. a reflow to be triggered after all the alterations have finished?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:17:55+00:00Added an answer on June 7, 2026 at 4:17 pm

    There are several ways. The primary goal with all of them is that you end up causing a single – or at least as few as possible – reflows/repaints.

    Off-DOM element

    You can work with elements without appending to the DOM, and then just append everything together once everything’s set up.

    The only issue with this is if your code needs to reference offset dimensions, since elements not yet in the DOM do not have any.

    var container = document.createElement('section'); //not in the DOM yet
    //do some extensive work here to prepare the doc
    document.body.appendChild(container); //now we go to the DOM, causing a single re-paint
    

    Doc fragment

    A more formalised, and possible improved, variation on this theme would be document fragments, which bring a performance benefit (apparently). They’re effectively a second, separate DOM that has no display.

    String

    Probably the quickest of all of these would be to build up your document as a string. The obvious implication is you can’t use DOM methods on it, but if you’re happy string-handling and REGEX’ing (not ideal on HTML, of course), could be worth considering.

    Finally, if speed is of the essence and you have a LOT of computation or string-handling to do, you might want to harness web workers. These can’t talk to the DOM directly, but you can outsource tasks to them and, crucially, they work asynchronously on a separate thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say in my js file I want to have var NO = 0; var
Say I have some pixel buffer associated with variable: CVPixelBufferRef a; I want to
Say, when I convert a string into a byte array using single-byte encoding, some
Say I want to make a regex that splits a optional version number from
Say we have two sequences and we and we want to combine them using
Say I have a textbox in HTML using the following code: <input type=text name=text
Say for example I have a textview in class A, and I want to
Say you have a page callback from Module #1 using hook_menu(). You want to
Say I have a Telerik MVC Grid, AJAX bound and I want to put
Say I have a SSI script that uses exec, or a PHP script that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.