0

I have a html div (containts placeholder text) that I'm editing via JS everytime the page loads (to the same updated content most of the time).

This data is pulled from the server.

Is there a way to cache this content in the browser so that when the page loads, the cached content is shown, and then update it when the server call is completed (most likely, this will be the exact same content, so the delay won't be noticeable to the user).

The goal here is to reduce the delay between placeholder text and real content from the server.

EDIT: I don't have a backend. Everything here is client side.

Pranay Prakash
  • 358
  • 4
  • 13
  • I'm doing that to reduce delay between the moment the JS function runs and the moment the server replies with content. I want to be able to reduce the delay between the page loading and the JS file loading. I'm hoping browser caches can help me with this. – Pranay Prakash Feb 23 '16 at 05:13
  • Possibly a duplicate http://stackoverflow.com/questions/650440/cache-ajax-requests – Vinny M Feb 23 '16 at 05:43

1 Answers1

0

The best way to deal with these kinds of problem is to make a backend call and then render html at server side. So the page when load on client side you will see everything in place.

Now further interactivity can be attached using js.

So here is the flow:

  1. Client request the page
  2. Server makes a separate call to that service which provides the data
  3. Construct html page on server side using that data, u can use handlebars for the same
  4. Send the html thereafter
  5. Apply js events on that div once the page loads
Avinash Agrawal
  • 1,038
  • 1
  • 11
  • 17