helmgast / lore

A web-based storytelling framework.
4 stars 0 forks source link

Caching and performance analysis #51

Open ripperdoc opened 10 years ago

ripperdoc commented 10 years ago

We need to cache to do a public website, rather than generating template on the fly. But some parts of the current templates, e.g. the header with user name, will be unique for every user and therefore add very little caching value. We need to find a way to cache most of the page (e.g. mainly the articles).

Some more details:

Overall, we shouldn't rush to cache anything until we have researched performance. Such as:

Consider these articles before starting: https://amphtml.wordpress.com/2015/12/16/why-amp-is-fast/ http://flask.pocoo.org/docs/0.10/patterns/caching/ http://brunorocha.org/python/flask/using-flask-cache.html https://pythonhosted.org/Flask-Cache/ https://serversforhackers.com/nginx-caching/

Also, this is fundamental for the total performance: https://developers.google.com/web/fundamentals/performance/

ripperdoc commented 9 years ago

And this link: https://jonsuh.com/blog/need-for-speed-2/

http://stackoverflow.com/questions/135657/tool-to-identify-unused-css-definitions/3113120#3113120

https://www.smashingmagazine.com/2016/12/front-end-performance-checklist-2017-pdf-pages/

ripperdoc commented 3 years ago

New take on caching strategy: Set a flag on g object whether the request is cache-control: public or private. Make it public by default, but any function that in template will result in a variation based on the user, can be publicly cached. So any such function should set the flag to private.

Note that there are other variations that may create stale content in cache, such as outputting HTML that depends on current time (typical example: relative dates).

As the root header includes user data, currently virtually all templates would be private cached. But if we remove that part, and fetch it with jquery, it would make lots of them publicly cached.

What should make a template private cached:

Wait, a problem: if we publicly cached the the unprivileged version, won’t the privileged ones also get that, as their request never continues to the Flask server? We can use Vary header for this, but if we put Vary on the cookie/user, it would almost never cache publicly

We can add headers to the Nginx cache key, to ensure we cache different versions. We need to make sure a privileged and unprivileged page gets different cache keys. We could: