Skip to content

Commit 19e00bd

Browse files
author
Peter Bengtsson
authored
delayed css for pages that are not in a rush (#422)
1 parent 60a7157 commit 19e00bd

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

peterbecom/base/jinja2/base.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ <h1 class="ui header">{% block page_title %}{{ page_title }}{% endblock %}</h1>
148148
{% block basejs %}
149149
{%- if request.path == '/plog/blogitem-040601-1' %}
150150
{% javascript 'lyrics' %}
151+
{% javascript 'delayedcss' %}
151152
{% else %}
152153
{% javascript 'base' %}
153-
{% endif -%}
154154
{% javascript 'cssrelpreload' %}
155+
{% endif -%}
156+
155157
{% endblock %}
156158

157159
{% block extrajs %}{% endblock %}

peterbecom/base/static/css/peterbe.css

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*! peterbe.css */
2+
13
body {
24
color: #333;
35
background-color: #ffffff;
@@ -227,9 +229,9 @@ span.not-approved {
227229
color: rgba(0, 0, 0, 0.4);
228230
font-size: 0.875em;
229231
}
230-
.ui.comments .comment .metadata a {
232+
.ui.comments .comment a.metadata {
231233
color: rgba(0, 0, 0, 0.4);
232234
}
233-
.ui.comments .comment .metadata a:hover {
235+
.ui.comments .comment a.metadata:hover {
234236
color: rgba(0, 0, 0, 0.8);
235237
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(function() {
2+
'use strict';
3+
4+
window.setTimeout(function() {
5+
var links = document.getElementsByTagName('link');
6+
var len = links.length;
7+
for (var i = 0; i < len; i++) {
8+
var link = links[i];
9+
if (link.rel === 'preload' && link.getAttribute('media') === 'delayed') {
10+
link.setAttribute('media', 'all');
11+
link.rel = 'stylesheet';
12+
}
13+
}
14+
}, 1000);
15+
})();

peterbecom/mincss_response.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,17 @@ def mincss_html(html, abs_uri):
122122

123123
found_link_hrefs = list(result["stylesheetContents"].keys())
124124

125-
# print("ABS_URI:", abs_uri)
126-
template = (
127-
'<link rel="preload" href="{url}" as="style" '
128-
"onload=\"this.onload=null;this.rel='stylesheet'\">\n"
129-
'<noscript><link rel="stylesheet" href="{url}"></noscript>'
130-
)
125+
if abs_uri.endswith("/plog/blogitem-040601-1"):
126+
template = (
127+
'<link rel="preload" href="{url}" as="style" media="delayed">\n'
128+
'<noscript><link rel="stylesheet" href="{url}"></noscript>'
129+
)
130+
else:
131+
template = (
132+
'<link rel="preload" href="{url}" as="style" '
133+
"onload=\"this.onload=null;this.rel='stylesheet'\">\n"
134+
'<noscript><link rel="stylesheet" href="{url}"></noscript>'
135+
)
131136

132137
def equal_uris(uri1, uri2):
133138
# If any one of them is relative, compare their paths

peterbecom/plog/jinja2/plog/post.html

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ <h4><a href="{{ post.url }}">{{ post.url }}</a></h4>
8888

8989
{% block content %}
9090

91-
<!-- request.path="{{request.path}}" -->
9291
{% if request.path != '/plog/blogitem-040601-1' %}
9392
<div class="bsa-cpc"></div>
9493
{% endif %}

peterbecom/settings/bundles.py

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
"output_filename": "js/cssrelpreload.min.js",
9898
"extra_context": {"async": True},
9999
},
100+
"delayedcss": {
101+
"source_filenames": ("js/delayedcss.js",),
102+
"output_filename": "js/delayedcss.min.js",
103+
"extra_context": {"defer": True},
104+
},
100105
# 'warmup_songsearch': {
101106
# 'source_filenames': (
102107
# 'plog/js/warmup-songsearch.js',

0 commit comments

Comments
 (0)