Is it possible for ExpressJs compression to compress more than just static files on an HTTP request?

I am currently using Express 4.x and I have implemented compression middleware in my app.js file like so:

var compression = require('compression');

var app = express();

app.use(compression());
app.use('/',               require('./static'));
app.use('/api/xxx',        require('./api/xxx'));

Upon inspecting the Safari web inspector, I noticed that certain files such as my app.js are indeed compressed, resulting in a slight decrease in file size:

https://i.sstatic.net/QBvHd.png

However, other files such as API requests do not appear to be compressed:

https://i.sstatic.net/KIjwM.png

Given that my server simply responds with JSON data upon request, I am curious as to why the transferred data is not more heavily compressed?

Answer №1

The reason for this is that you must adjust the compression level to achieve the desired result.

To learn more, refer to the official documentation here: https://github.com/expressjs/compression

My settings are configured for maximum compression as shown below:

// Configure content compression
app.use(compression({
    level: 9,
    memLevel: 9
}));

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

Angular and Ionic Framework Highchart: Troubleshooting the Issue

I am trying to create a graph on my web application. However, I am struggling to understand how to integrate Angular with Highcharts. I am utilizing the highcharts-ng library from github.com/pablojim and the Ionic framework from ionicframework.com. I be ...

How can JavaScript be utilized to iterate through regex matches and divide a string into an array of segments separated by hyperlinks?

After receiving a string from an api, it appears like this: "If you <a href='https://example.com'>Click here</a> then <a href='https://example.net'>Click here</a>." I aim to construct an array that mir ...

Execute a JavaScript function when an element loaded via Ajax in a Spring MVC framework triggers the onChange event

I currently have a dropdown list with two values and I am looking to enable or disable four components based on the user's selection. If the user picks the first value, the components should be enabled, otherwise they should be disabled. On the main ...

What are the benefits of defining a function before using it as opposed to immediately invoking it?

Despite attempting to search for the solution on Google, I seem to struggle with addressing the issue as I keep coming across irrelevant topics. I am curious about the variance between: this.on('click',thisismyfunction ); and: this.on('c ...

Find the item that has a specific value in its sub-property

Information Models: public class Header{ public int Identifier; public int value; public bool anotherValue; public List<Trailer> trailers; } public class Trailer{ public int ID; public Language MyLanguage; public string ...

Show data in a popup using jQuery DataTables and loading content asynchronously via Ajax

I am attempting to display a list in a popup based on an Ajax request. Prior to the Ajax call, the list is contained within the popup. However, after the Ajax request, the list remains on the page instead of inside the popup, and the old list still appears ...

Angular 6 - Consistently returning a value of -1

I'm facing an issue with updating a record in my service where the changes are not being reflected in the component's data. listData contains all the necessary information. All variables have relevant data stored in them. For example: 1, 1, my ...

Using Javascript to determine the frequency of a JSON array with ESLINT version 6

I'm struggling to create an algorithm that counts the occurrences while adhering to ESLint's strict standards in JavaScript. Here is my input table: [ { "id": 2, "name": "Health", "color": "0190fe" }, { "id": 3, "name": ...

How can I stop VSC from automatically inserting "require"?

Every time I edit certain JS files in VSC, it automatically inserts "require()" calls that I then have to delete. Is there a way to stop VSC from adding these lines with "require"? Appreciate any help, Didier ...

Encountering an NG201 error while trying to launch the server with express in Angular

I encountered the NG201 error attached below and I'm having trouble pinpointing its origin. After researching, I found that @Injectable and provideIn settings were configured in the dataService class, which is my sole service. Upon building the app wi ...

Switching up the content of an HTML page with JavaScript or JQuery: what you need

Is it possible to update HTML content using JavaScript or JQuery? https://i.sstatic.net/EWOXg.png I am trying to change the contents from 1 to 5 in a sequential order based on the time shown in the image. How can I achieve this using JavaScript or JQuery ...

Unable to locate module specifier three

Currently, I am working on Three.js in three different modules and using Express as the backend server. In my console, I keep encountering the error: "Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with eith ...

What is the reason for the user not being defined in this scenario?

I am struggling to understand why I cannot set the user in the app. Registration and login functionalities are working fine. However, after refreshing the app, the user data is lost while the access token remains intact. Additionally, when attempting to cr ...

Combining HTML, CSS, JAVASCRIPT, and PHP for a seamless web development experience

As a beginner in web development, I have some knowledge of javascript, html, css and am currently delving into php. However, I am struggling to find comprehensive resources that show how to integrate all these languages together. I would greatly appreciat ...

To ensure the react page is not rendered until the script has finished executing, follow these steps in React

Upon fetching data from an API using my script, I encounter a challenge where the react page loads before the script finishes loading. As a result, I end up with a page lacking necessary information and have to refresh in order to see the updates. The ma ...

Encountering a "Raphael is undefined" error message when working with Treant.js

I need help creating an organizational flow chart using treant.js. Below is my code snippet, but I'm encountering a 'Raphael is not defined' error that I can't seem to solve. Can someone please assist me with identifying the root cause ...

What steps can be taken to prevent users from dragging a page horizontally?

One function on my site involves a horizontal scroll that animates the DIV to the left when a button is clicked. The element's width is set at 18000px, ensuring it has a horizontal scrollbar that I have since disabled. Despite this, users are still ...

Eliminate the console.log messages from Workbox in Next.js

Does anyone know how to stop the constant stream of console.log messages from workbox in a NextJS project? I recently initiated a new repository and it's flooding me with unnecessary informationhttps://i.sstatic.net/Aikrx.jpg ...

Preserve data across all pages using sessions

On my website, I have a pagination system where each page displays 10 data entries. Whenever a user clicks on the pagination buttons, it triggers a request to the database to fetch the corresponding records. Each data entry also includes a button that can ...

Utilize specific CSS attributes from a class and apply them to a DOM element

It's clear that the question at hand is more complex than it initially appears. I'm not just looking for a way to apply a CSS class to a DOM element, as I'm already familiar with that (<div class="MyCssCLass"></div>) My goal is ...