The page comes to a standstill while trying to read through a hefty JSON

Is there a way to improve the user interface when loading an 8MB json file using JSON.parse in Javascript? The page freezes for about 1-2 minutes, so I'm wondering if it's possible to parse async and display a loading or percentage info.

I came across jsonstream (https://github.com/dominictarr/JSONStream), but I believe it's for nodejs and I couldn't quite understand it.

If anyone has a simple example or solution to share, I would greatly appreciate it. Thank you!

Answer №1

If you're looking for a way to improve performance, consider utilizing web workers. By moving the parsing process into a separate thread using web workers, you can parse your file asynchronously.

For example, you can have main.js and worker.js in your project. In main.js, you could implement something like this:

var myWorker = new Worker("worker.js");
myWorker.postMessage(jsonValue); //jsonValue represents your JSON file

myWorker.onmessage = function(e) {
  var parsedJSON = e.data;
  console.log('Message received from worker', parsedJSON);
}

In your worker.js file, you could have the following code:

onmessage = function(e) {
  var parsedJSON = JSON.parse(e.data)
  postMessage(parsedJSON);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Bootstrap's form-inline element causing incorrect spacing in btn-group

I'm having an issue with Bootstrap components. When I try to input numbers, everything works fine as long as I don't use form-inline or a navbar. Check out my fiddle here: http://fiddle.jshell.net/6Lrhcezb/ https://i.sstatic.net/hzmlM.png The ...

Identify any missing periods and combine the years into a single range

I am working on restructuring year ranges with gaps and consolidating them. For example, converting [{start: 2002, end: 2020}, {start: 2020, end: null}] to {start: 2002, end: null} or [{2002, 2004},{2006, 2008}, {2008, null}] to [{2002-2004}, {2006-null}]. ...

Python Eve encountering WSGI issue [Errno 32] causing a broken pipe during an Ajax call

As I operate a simplistic wsgi server, from run import app if __name__ == "__main__": app.run(threaded=True, debug=True) When I send a get request to the server, it responds with a 200 message but no data. An error message is displayed: Error on r ...

Place the image either above or below the text in a relative position

I have a peculiar dilemma that has been on my mind lately. As I work on designing my website, I am nearing completion of the responsive/mobile view. Currently, everything looks fine, but only because I use display: none; to hide images when the viewport is ...

Is there a method for creating a JSON DTD template that allows for the mapping of JSON REST APIs back to the client in a universal manner through configuration settings?

Is there a standard JSON schema that would enable users to configure a generic connector for external REST APIs returning JSON, allowing them to map properties from the API to properties in their applications? ...

Executing a call back function after a successful POST, PUT, or DELETE request can be achieved through redux-observable

I have been using the code below for performing GET, POST, PUT, DELETE calls. While it works perfectly fine for GET requests, I am encountering an issue with entering the success(mergeMap) block for POST, PUT, and DELETE requests. Despite receiving a statu ...

Comparing AngularJS controller and template encapsulation to Angular components: a breakdown

I've set up a state in my angularjs app called homeInside, complete with its own controller and template. Within that layout, I have various elements including a button with an ng-click event tied to the function doSomething. Additionally, there is an ...

Issue with Vuex and Jest - Accessing undefined property <getterName>

Currently, I am attempting to utilize Jest for testing a Vue component that relies on a getter in Vuex. The getter is structured to return a function that ultimately provides an array: questions: state => pageNumber => state.pages[pageNumber].questi ...

Implementing a JSON query with an onkeyup event listener

My main objective with this code is to trigger a json query request by using a textfield to specify the location. It's essentially a quick search feature that searches for specific content on a different website. For example, if I input www.calsolum/ ...

Is it possible to utilize JSX when developing an App using React CDN or the CRA (create-react-app) boilerplate template?

The HTML Code: <div id="app"></div> <script src="https://unpkg.com/react@latest/umd/react.development.js" crossorigin></script> <script src="https://unpkg.com/react-dom@latest/umd/react-dom.develo ...

Using JavaScript code to sift through and eliminate irrelevant data

Recently, I started learning about angular js and came across a link from which I need to extract a list of names and ids. I successfully retrieved the list in json format, but now I need to filter out unwanted items. The criteria for filtering is based ...

JS: delay onClick function execution until a page refresh occurs

Currently, I am working on a WordPress site that involves a form submission process. Upon successful submission, a new post is created. After the user submits the form, I have implemented JavaScript to prompt them to share a tweet with dynamically prepopu ...

Utilizing AJAX and PHP to dynamically update MYSQL database via a dropdown selection

I am currently facing an issue with running SQL queries through AJAX after the selection in a dropdown box changes. I would appreciate any assistance that can be offered. Context My task involves creating a daily calendar for a gym to display all the clas ...

The specified variable is not present within the for loop

This script dynamically generates table rows for each client, populating each row with specific values such as name, IP address, operating system, country, and time. These values are stored in an object or dictionary named clientel. The setup of the progr ...

Interacting with a WebGL globe: accessing database information and displaying pop-up windows when clicking on specific locations on the globe

I am working on creating a WebGL Globe similar to the one found at this link: Currently, I have been using this example as a reference point: Here are the specific project requirements that I am aiming to achieve: The website needs to be able to manage ...

What is causing ES6 Class properties to be concealed by Higher Order Functions?

UPDATE: Added new screenshots to provide clarity at the end. My current challenge involves utilizing high order functions to combine subclasses/mixins. I've noticed that I can only access properties from the first class I extend, and only properties ...

Initiate a jQuery modal dialogue box

As an apprentice with no prior experience working with JavaScript, I encountered a problem with my function that calls a popup. The function works fine on the first button, but fails to work on all subsequent buttons. Since the application keeps adding b ...

Internet Explorer does not return results when using AJAX during the onchange event (specifically for IE only

My code is functioning correctly on other browsers, however in IE it does not provide any result when I select the dropdown button. Instead, it changes and displays an empty result. This is my AJAX: $("#book").change(function(){ var DOMBULK = $(" ...

When attempting to rotate a sphere in threejs, the rotation may not function properly if a loop is

I am attempting to rotate a sphere a specified number of times when a button is clicked (with the user selecting the number of rotations). To achieve this, I have implemented a for loop: $('#clickme').on('click', function () { var ...

What is the process for transforming FormData into an Object and then converting it into a JSON string

Is there a way to convert FormData into an object and then use JSON.stringify on it? I suspect that my API isn't populating values correctly because it expects data in JSON format. handleSubmit: handleSubmit(event) { event.preventDefault(); ...