How long does it take for node and express to load classes in milliseconds

Currently, I am utilizing node express without the use of a template engine. Instead, I am creating my HTML file and sending it through response.send(template); which has been working well for me thus far.

However, as I begin incorporating more complex tags like checkboxes with multiple classes, I have noticed a slight delay in loading these classes when accessing the route in the browser. This results in the checkbox initially appearing before transforming into a button after a few milliseconds. While this timing issue may seem minimal, I am wondering if there is a way to preload the classes before displaying the page?

Are template engines such as handlebars or pug capable of addressing this particular feature?

I would greatly appreciate any guidance on where to focus my attention. Thank you!

Answer №1

Utilizing a template engine such as ejs or pug, enables you to leverage the res.render(...) function. This function facilitates retrieving data from the server side and sending it to the client alongside the page content.

For instance:

const express = require('express');
const app = express();

app.use('view engine', 'ejs'); // Specify your preferred view engine here

app.get('/path/to/my/page', function(req, res) {
    // Retrieve data
    res.render('example', { data: 'my-found-data' }); // Render the 'example' template with the fetched data
}

For more detailed information on utilizing template engines, refer to the official ExpressJS documentation available at:

https://expressjs.com/en/guide/using-template-engines.html

Answer №2

Can you explain what is meant by classes in this context?

Is there a way to preload the classes before displaying the page?

Are you referring to CSS classes? If so, you can include a link to load the CSS in the header of the HTML document where it's being used.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Authorization Required</title>
  <link rel="stylesheet" href="/assets/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <link rel="icon" href="/favicon.ico" type="image/x-icon">
  <meta name="description" content="">
  <meta name="Keywords" content="">
  <meta name="robots" content="noindex">
</head>
<body>

For example:

<link rel="stylesheet" href="/assets/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

This code snippet loads bootstrap.min.css from /assets/bootstrap.min.css, and since it's placed in the header section of the page, all CSS classes are loaded before the browser begins rendering the page, ensuring proper display.

For more information on loading CSS, visit https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics.

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

Upon inserting Node 5, an error with the code EINVALIDTYPE occurred in npm

Recently, after I upgraded to Node 5, I've been encountering an error in the terminal every time I try running anything with npm. npm -v: 2.14.12 Desperately attempting to update npm to the latest version: MacBook-Pro-de-MarceloRS:promo-auto-loan ...

Learn how to create a button that will only submit a value when clicked using Node.js and EJS

Currently in my ejs file, I have a button that sends a value to app.js instantly when the program runs. However, I want it to only submit the value when clicked by the user. <% notesArray.forEach((note,i) =>{ %> <div class="note"> ...

Is Node.js the ultimate tool for JavaScript manipulation?

I'm looking to streamline my development process by building a generator with node.js. My goal is to have the ability to modify and generate node.js module files, insert comments into the files, and more. For example, I want to generate the API endpo ...

I encountered an issue while trying to install the newest nodejs package on my Parrot OS. Despite having version 12 already installed, I ran into problems when attempting to create a new React app

error: npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/n npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/n' npm ERR! [Error: EACCES: permission denied, mkdir ...

Shutting down several ports with an Express application

Currently, my app is running on multiple server instances on different ports. I achieve this by using the command "npm run node_1 & npm run node_2", which runs the app on localhost at ports 3001 and 3002. The issue arises when I attempt to close the applic ...

Troubleshooting Problems with JSON Parsing in Node.js

After retrieving a JSON file and utilizing NodeJS to parse it, the structure of the JSON file appears as follows: { "id": 5, "x": 9.996, "y": 0.135, "v": { "x1": 0.653, "y1": -0.064 }, "z": 1.4730991609821347 }, { ...

Facing an ERR_SSL_PROTOCOL_ERROR while working with Heroku, Node.js, Express, and SSL encryption

Lately, I activated SSL for my website hosted on Heroku, wildcodemonkey.com, but Chrome shows me the error "ERR_SSL_PROTOCOL_ERROR" whenever I try to access it. From what I've gathered, the SSL connection ends at Heroku's router, which then forw ...

Tips on utilizing recursive Promises within a loop while transferring arguments to another function

Despite searching other threads on SO, I couldn't find a satisfactory answer to my problem. Every solution seems to be missing something essential for my case, especially since none of them address Apple Music specifically. The Apple API relies heavil ...

Utilizing the MEAN stack to establish a connection with a simulated data collection

Currently, I am diving into the world of M.E.A.N stack development. As part of my learning process, I have successfully set up a test page where Angular.js beautifully displays and re-orders data based on search criteria. To challenge myself further, I dec ...

Initiate the node.js server automatically upon Windows 8 startup

Seeking advice on setting up a node.js server to run automatically on startup in Windows. Additionally, I want to launch a standalone application after the server starts. Any recommendations on the most efficient way to achieve this? ...

Is MongooseDB the Best Place to Save Your Calculations?

Currently, I am utilizing the MERN stack for my project. The task at hand involves creating an application that allows a user to input four numbers. My goal is to store all possible combinations of these four numbers in a database without revealing them ...

Having trouble bringing in @tensorflow-models library in node.js

Recently, I started delving into the world of node.js and encountered an issue with importing TensorFlow js models into my application. Here is the snippet of code I attempted to use: import * as cocoSsd from '@tensorflow-models/coco-ssd' const ...

Bundling sub-components using Rollup for NodeJS application packaging

My ES6 library consists of several sub-modules arranged like this: - package.json - lib - my_package - file1.js - file2.js - sub_module1 - file3.js - file4.js Currently, I import modules within my package using file resolution r ...

403 Forbidden - PUT https://registry.npmjs.org/shah - Access Denied: You are not authorized to release the package "shah". Please ensure you are logged in with the appropriate credentials

Currently in the process of developing a reactjs component library for npm. I've followed all the necessary steps, but encountering an issue when trying to publish via npm. Despite spending over an hour searching on Google, I haven't been able t ...

Upon a successful AJAX post request, the page fails to display

I'm encountering an issue connecting my front-end JavaScript to my back-end Node/Express. Although the requests from my client-side js to the server return successful, the page I am requesting fails to render. On the server side, here is my code: ap ...

Having difficulty removing the node_modules directory

I am attempting to remove the node modules directory from my project in order to reinstall npm i because I encountered errors while running npm scripts (I suspect node_modules corruption), but unfortunately, I am unable to do so. My attempts include: Try ...

jade, express, as well as findings from mysql

My goal is to display the results of an SQL query in Jade, which pulls data from a table of banners. Each banner has a unique id and falls under one of three types. Here is my current code : express : connection.query("SELECT * FROM banner_idx ORDER BY ...

Having trouble retrieving data from the database when passing input to a mongoose query using an href tag in Node.js

Welcome to My Schema const AutomationSchema=new mongoose.Schema( {EventName:String, EventDate:String, EventLocation:String, EventDetails:String } ) The Events Model const EventsModel=new mongoose.model("Events",AutomationSchema ...

I'm having trouble locating the socket.io.js file when using Node.js with Express and Socket.IO

While working on a node js application that involved socket.io, I sought help from SO but couldn't find a solution for my specific issue. The error message I encountered is as follows: Failed to load resource: the server responded with a status of 4 ...

What steps should be followed to execute this moment.js code in an Angular.js controller using Node.js?

I am trying to adapt the following node.js code that uses moment.js into an AngularJS controller: var myDate = new Date("2008-01-01"); myDate.setMonth(myDate.getMonth() + 13); var answer = moment(myDate).format('YYYY-MM-DD'); To achieve this, I ...