Invalidation of the cache of web browser

Introduction

To avoid problems with too long storage of static files in the cache of web browser  the platform has the mechanism of the cache was invalidated when the server is restarted.

The mechanism works as follows:

  1. When the application is restarted, a special variable cache_invalidator is randomly generated.
  2. This variable is appended to the address for all static resources as follows (@cache_invalidator@ is the content of variable):

<img src=’/static/img/image.png?@cache_invalidator@’>

Usage of invalidators

Invalidator is a function which converts the address of the static resources adding to them @cache_invalidator@.

HTML

To add a string of invalidator to html templates of flask you need to use the macro getStaticUrl (defined in the file src/templates/macros/get_url_with_prefix.html).

Example of usage:

<link href=”{{ getStaticUrl(‘css/bootstrap.min.css’) }}” rel=”stylesheet”>

JavaScript

JS Interface is the function getStaticUrl( ) defined in the basic template src/templates/base.html.

Example of usage:

var path = getStaticUrl(‘/static/js/script.js’);

 

ShareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VKEmail this to someone