A
A
Aklaim2014-10-15 17:29:03
PHP
Aklaim, 2014-10-15 17:29:03

How to add authorized user data to cached page?

Faced the problem of caching statics using nginx.
The cached page contains the data of an authorized user; naturally, they cannot be cached, so you have to insert them using SSI.
That is, in the html code of the page there is an SSI insert of the form:
<--#include virtual="/user/render"-->
When the page is rendered, nginx detects the SSI insert, it will contact the specified address and replace the SSI with the received response.
In principle, this works, but I would like to know how similar functionality can be done differently?
I don’t really like the option of loading user data using js, since at first it will seem to the user that he is not authorized (approximately how aliexpress works).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2014-10-16
@Aklaim

I do it with javascript. Why don't you like the solution? In the place in the header of the site where we have the avatar + username and icon of his menu, I display the default "stub" and a rotating spinner. We check the local cookie, if authorized - display the avatar + name there, not authorized - display links to login and registration. If this is done with light animation, it looks quite great. If there is no cookie, then this "stub" can be seen for 0.5-3 seconds, depending on how long the script will communicate with the server, but if there is a cookie, then most often no one will notice anything at all. In order to shorten FOUC, this script is in the html itself, right in the right place. In order not to wait for all downloads, etc. and be done as quickly as possible.

S
Sergey Sokolov, 2014-10-15
@sergiks

As an option - JS can immediately assume that the user is authorized - by cookies.
It's not clear to me why the existing SSI option is bad.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question