How to effectively cache via php scripts when JS is disabled on the site, how to cache when there are js and when ajax request is used.

  • to cache what? - hardworm

1 answer 1

For a start, a couple of lines of theory. Php scripts run on the server, js - in the browser of the local computer. (There are, of course, node.js and stuff, but judging by the question, we are talking about the most common sites based on php.)

php forms a page in html + js code for transmission to a local browser.

js runs in a local browser. js can initiate an ajax request to the server (executing a piece of php code on the server) to get some data from the server (for example, a sample from the product database).

Caching is the process of remembering on the server (in memory, in a file) the page code received by html + js and issuing it on request to the server.

Now to the question. Caching is performed on the server side either by server-side packages like Varnish or php-plug-ins. The page is remembered in the html + php code before being issued to the visitor's browser. On the next access, if the page has not changed, the php code will not be called, but the page "cast" will be quickly issued.

Part of the question "when JS is disabled on the site" contains inaccuracies. The site can not disable js, because it is not there. js can only be disabled in the browser. In theory. Because after that 90% of modern sites will stop working.

However, it does not matter for the caching process. In any case, the server remembers html + js.

Caching ajax request is impossible in principle, i.e. by definition. The whole point of ajax request from a browser on a home computer to a server in a conditional Chicago is to get new data and display it on a page. However, the volume of this data is usually small.

It is possible that a 100% cached page gives an ajax request when you press a button and locally changes a small part of its content on the visitor’s computer. It has nothing to do with the cache.

The cache is needed to quickly issue the initial content of the page.

Summing up.

  1. There is no difference how to cache when js is turned on or off in the user's browser . On the server, js is not executed, but in any case is added via php to the page code.
  2. Unable to cache ajax request.
  • Well now more to the point) - Zimzibar