Caching data using hidden divs

I am trying to speed up the response time in my ajax web application by doing the following:

Say that the user requests a page whose contents do not change (for example, a web form). When the user makes another request, I "cache" the form by placing it in a hidden div. Before displaying new information. Thus, the form is basically still loaded in the browser, but not displayed to the user. If the user requests the same form again, it is loaded from a hidden div. This is noticeably faster than server feedback for the form.

I really understand that with a lot of data, performance is likely to deteriorate as the browser gets a lot of memory. But I will put a limit on how much is "cached" in this way.

Now I have come up with this myself, so I would like to know if there is a better / established way to do this. It works as expected, but I don’t know what are the possible flaws (possibly related to security?).

I would be grateful for any suggestions. Many thanks.

+3
source share
5 answers

I have done this before. This can be a useful technique. Just make sure the data is accurate and you support disabled JS user agents.

EDIT: And that there is no better solution.

+2

HTML- JS, , , div HTML- ( + + ).

, JS:

<script language="javascript">
var myFormCode = '<? echo $myFormCode; ?>';
</script>

( PHP... )

, JSON:

<?php
  echo json_encode($myFormCode);
?>

... , - :

<script language="javascript">
  myRealFormDiv.innerHTML = eval(myJSONEncodedTextIGotViaAJAX);
</script>

JS-, , , , , , .

+1

, . - , , - .

+1

APC Memcached?

html , " ", ( css? IE6?) ?)

, , , .

-1

- HTTP "Expires" "Cache-Control" .

If you set the "Expires" header for 1 hour in the future for url http://example.com/form.html, then the next time within an hour when the user goes to this form, the HTML will be loaded without touching the server.

If you correctly place your images / CSS / JS and give them the "Expires" headers in the future, then there will be no server transition, plus you can improve the performance of other pages.

-1
source

Source: https://habr.com/ru/post/1724640/


All Articles