Commit ff25747d authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

keep in cache the url computed for sstatic

parent 30bc2dc6
Pipeline #14211 passed with stage
in 29 seconds
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
{% load static %}
{% load sstatic %}
{% load basetheme_bootstrap %}
{% load i18n %}
......@@ -19,9 +18,9 @@
<link href="" rel="stylesheet">
<link rel="stylesheet"
<link rel="stylesheet" href="{% static '/css/bootstrap-multiselect.css' %}" type="text/css"/>
<link rel="stylesheet" href="{% static '/css/basetheme_bootstrap4_pasteur.css' %}"/>
<link rel="stylesheet" href="{% static '/css/fonts.css' %}"/>
<link rel="stylesheet" href="{% sstatic '/css/bootstrap-multiselect.css' %}" type="text/css"/>
<link rel="stylesheet" href="{% sstatic '/css/basetheme_bootstrap4_pasteur.css' %}"/>
<link rel="stylesheet" href="{% sstatic '/css/fonts.css' %}"/>
{% block extra_css %}{% endblock %}
<body class="d-flex flex-column h-100">
......@@ -187,12 +186,12 @@
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script type="text/javascript" src="{% static '/js/bootstrap-multiselect.js' %}"></script>
<script type="text/javascript" src="{% sstatic '/js/bootstrap-multiselect.js' %}"></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src="{% static '/js/basetheme_bootstrap.js' %}"></script>
<script src="{% sstatic '/js/basetheme_bootstrap.js' %}"></script>
{% block extra_js %}{% endblock %}
......@@ -4,6 +4,7 @@ import string
from django import template
from django.conf import settings
from django.core.cache import cache
# credits :
......@@ -12,15 +13,27 @@ register = template.Library()
def sstatic(path):
url = cache.get(path)
if url:
return url
url = compute_url_for_path(path)
cache.set(path, url, None)
return url
def compute_url_for_path(path):
Returns absolute URL to static file with versioning.
full_path = os.path.join(settings.STATIC_ROOT, path[1:] if path[0] == '/' else path)
full_path = os.path.join(settings.STATIC_ROOT, path[1:] if path[0] == '/' else path)
# Get file modification time.
mtime = os.path.getmtime(full_path)
return '%s%s?%s' % (settings.STATIC_URL[:-1], path, mtime)
except OSError:
except TypeError:
# Returns normal url if this file was not found in filesystem.
return '%s%s?%s' % (settings.STATIC_URL[:-1], path, ''.join(
random.choice(''.join((string.ascii_letters, string.digits))) for _ in range(32)))
random.choice(''.join((string.ascii_letters, string.digits))) for _ in range(4)))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment