skip to Main Content

Why server updates doesn’t reflect on client browser, Maybe an attribute value should be changed ?, something related to caching ?

app.get('/hello' , (_ , res) => {
    res.header({
        'Cache-Control': 'no-cache'
    });
    res.json('HelloWorld');
});

that should help but it didn’t !

2

Answers


  1. As mentioned in the comment, HTTP and HTTPS are a request and response protocol. You will only receive data from the server when you ask for it.

    If you want real-time changes from server to client, you can use WebSockets. They basically establish a connection between the client and the browser and events are triggered where you can share messages.

    Here is the API Documentation:
    https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API

    A slightly easier explanation:
    https://www.geeksforgeeks.org/what-is-web-socket-and-how-it-is-different-from-the-http/

    Login or Signup to reply.
  2. Note: each time you change/update some line of the code you need to save the code and restart the server in order for changes to take effect on client

    **if your are new to nodejs(express) "nodmon package" can help you reflecting the changes in client side from the serve side without need to restart the server each time you update some code.you only need you save the code.

    you can check details aboutt nodemon here.

    or follow the steps given below:-

    Step1: install nodemon by running the code below on terminal

     npm i nodemon
    

    **Step2: ** start the server with

    nodemon <server file name>
    eg.
    nodemon index.js
    

    now the changes you make on serve would be reflected to client without need to restart the server

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search