How can a modern browser retrieve a json.gz file without relying on external libraries?

What can be done to let the browser know that a json.gz file is compressed JSON, for example: {"abc":1}, and automatically unpack it into a JavaScript object?

I attempted this approach, but it was not successful: https://en.wikipedia.org/wiki/JSONP

<script src="http://localhost:8080/41925.json.gz?callback=parseResponse"></script>

The script from “http://localhost:8080/41925.json.gz?callback=parseResponse” was loaded even though its MIME type (“application/gzip”) is not a valid JavaScript MIME type.

I have the option to configure different headers on the backend, but I am unsure which ones to use.

Answer №1

For the fetch request to work, I included two headers: Content-Encoding with the value of gzip and Content-Type as application/json.

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

I’m having trouble identifying the error. Is there a possible infinite loop happening somewhere?

// JavaScript Document var person = prompt("ENTER INPUT", ""); var count = 0; var array = person.split(","); var freq = []; var words = []; // Commented lines removed for simplicity var i = 0, j = 0; while (array.length > 0) { var temp = array ...

Transform Yaml into Json data that has been sorted using Terraform

Is there a way to transform a YAML datasource into a sorted JSON file using Terraform? Here is an example of the YAML data: users: - key: 'user[0].name' value: Roku - key: 'user[0].age' value: '55' - key: ' ...

Encountered a match error exception while attempting to convert a JSON string

Check out this brief code snippet: val fileLine = s"""{"AP_details": [{"MAC_Address": "00:11:74:00:00:00"},{"MAC_Address": "00:11:74:00:00:00"},{"MAC_Address": "00:11:74:00:00:00"}]} """ val jsonAst = fileLine.parseJson import APDetai ...

How can I dynamically set the option attribute to "selected" and remove it when another option is chosen?

Before marking this as a duplicate, please read on: Initial Scenario: I am working with a select list and need to dynamically set the selected attribute when a specific option is chosen. Following Actions: Subsequently, when another option is selected fr ...

Attempting to convert PHP tables into PDF format by utilizing jsPDF-auto-table to generate a beautifully structured PDF file containing the results of a PHP query with multiple records

I'm new to stackoverflow but I find myself visiting it regularly for helpful tips. I've taken some code from the simple.html file that comes with the jsPDF auto-table plugin. However, I'm having trouble making it work with data generated by ...

Can the w regular expression pattern be modified to include special characters like é? If not, what other options are available?

Imagine having a regular expression that appears as follows: \w+ In this case, the string "helloworld" would be accepted: helloworld However, "héllowörld" would not pass the test: héllowörld The regex will stop at é (and also break atö) ev ...

Combining data from an element in a list with a state object in Redux

While experimenting with redux and reactjs, I came across an interesting scenario: I have a collection of items const items = [ {id: 0, name: 'one'}, {id: 1, name: 'two'}, {id: 2, name: 'three'} ] const itemsWithTheFl ...

Retrieve custom attributes of child elements using jQuery selectors

I am looking to modify the data-answersetid attribute of all child controls under the .cloneable class in a table. Each row in the table contains a single control - either a textarea, checkbox, radio button, or input[type=number]. Each control has a custom ...

The Render function in ReactJS is not getting refreshed

My goal is to implement a chat feature using material UI. I have set up a function where users can submit new chat messages, which then go through the reducer and are stored in the redux store. The process seems to be working fine, except for the fact that ...

What are the benefits of integrating firebase-admin-sdk with firebase-ui and firebase-client-sdk for both server-side and client-side authentication management?

I am currently working on implementing an authentication mechanism for my Next.js project. Specifically, I plan to utilize firebase-auth and firestore. My main goal is to keep important security logic on the server side to ensure safety. I want to avoid ex ...

Disable toolbar focus in TinyMCE

Is there a method to prevent the appearance of the white square known as "Focus to toolbar" in TinyMCE? Clarification: Upon pressing Alt+F10 in TinyMCE, a white square is outlined around a button on the toolbar. This allows navigation among toolbar butto ...

Issue with Bootstrap margins and padding

While creating an application form from scratch with Bootstrap, I encountered a peculiar issue. The element with ID officeaddress is missing from the HTML page upon loading. I've experimented with the my class in Bootstrap and attempted to add line br ...

Jackson Mixin: for deserializing route identifiers

I have implemented the Jackson Mixin for deserializing a mongo object and this is how my Mixin looks: public interface MyMixin { /** * Mixin to set key value for pojo. * @param key key * @param value value */ @JsonAnySetter void put(Stri ...

The parser was expecting an array to begin, but instead encountered an object at line 1, column 14738 in the path $.nodes[3

Whenever I try to read a JSON output using Retrofit, I keep getting the error: Expected BEGIN_ARRAY but found BEGIN_OBJECT at line 1, column 14738 in the path $.nodes[3].node.image I've tried everything to fix it but I just can't seem to fi ...

Is there a way to use JavaScript to add content to a document and then facilitate the download of that document?

Is there a way in JavaScript to write content to a JSON or TXT file and then download it, similar to how it is done in Python? const content = "Hello"; const link = document.createElement('a'); link.setAttribute('download', 'FileTo ...

Storing information without using nested data structures

Encountering an issue with saving a model containing nested attributes. I have two models - Person and Shirt. A Person has multiple Shirts associated with them. However, when attempting to save a Person using a JSON POST Request, only the Person is saved, ...

One property of a JavaScript object unable to be accessed by another property (which is a

I need some help with a problem I am encountering. Whenever I reference weekdays inside the function change_date(), Firebug shows an error message saying weekdays is undefined. Even when I tried using this.weekdays, the same issue occurred. How can I fix ...

Unable to convert the BSON type to a Date in MongoDB

I am currently facing an issue while attempting to filter data stored in MongoDB utilizing parameters from the URL. Whenever I send the request, the server crashes and displays the error message: can't convert from BSON type string to Date I attemp ...

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 ...

Angular Typescript filter function returning an empty arrayIn an Angular project, a

I have a filtering function in Angular that is returning an empty array. Despite trying similar solutions from previous questions, the issue persists. The function itself appears to be correct. Any assistance would be greatly appreciated. gifts represents ...