Skip to content

Commit 200f658

Browse files
Fetch jquery only once (#253)
* Apply formatting to html * Fetch jquery only once
1 parent e996549 commit 200f658

File tree

2 files changed

+113
-112
lines changed

2 files changed

+113
-112
lines changed

_layouts/default.html

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,34 @@
88
<!DOCTYPE html>
99
<html>
1010

11-
{% include head.html %}
11+
{% include head.html %}
1212

13-
<body>
13+
<body>
1414

15-
{% include header.html %}
15+
{% include header.html %}
1616

17-
{{ content }}
17+
{{ content }}
1818

19-
{% include footer.html %}
20-
21-
<script async>
22-
(function() {
23-
var font = document.createElement('link');
24-
font.type = 'text/css';
25-
font.rel = 'stylesheet';
26-
font.href = '//fonts.googleapis.com/css?family=Raleway:400,700';
27-
var s = document.getElementsByTagName('link')[0];
28-
s.parentNode.insertBefore(font, s);
29-
})();
30-
</script>
19+
{% include footer.html %}
20+
21+
<script async>
22+
(function () {
23+
var font = document.createElement('link');
24+
font.type = 'text/css';
25+
font.rel = 'stylesheet';
26+
font.href = '//fonts.googleapis.com/css?family=Raleway:400,700';
27+
var s = document.getElementsByTagName('link')[0];
28+
s.parentNode.insertBefore(font, s);
29+
})();
30+
</script>
3131

3232
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
33-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
34-
{% if site.analytics %}{% include analytics.html %}{% endif %}
35-
</body>
33+
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/dist/jquery-resizable.min.js"></script>
34+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
35+
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
36+
crossorigin="anonymous"></script>
37+
{% if site.analytics %}{% include analytics.html %}{% endif %}
38+
</body>
3639

3740
{% if site.url == 'https://training.play-with-docker.com' %}
3841
<script>
@@ -44,31 +47,29 @@
4447
}}();
4548
}
4649
{% if page.layout != 'post' %}
47-
48-
try {
49-
pwd.getUserInfo(function(pwduser){
50-
user = pwduser;
51-
if(user !== undefined){
52-
analytics.identify(user.provider_user_id,{"email":user.email});
53-
}
54-
else {
5550

56-
analytics.identify();
57-
}
58-
});
59-
}
60-
catch (error) {
61-
analytics.identify();
51+
try {
52+
pwd.getUserInfo(function (pwduser) {
53+
user = pwduser;
54+
if (user !== undefined) {
55+
analytics.identify(user.provider_user_id, { "email": user.email });
56+
}
57+
else {
58+
59+
analytics.identify();
60+
}
61+
});
62+
}
63+
catch (error) {
64+
analytics.identify();
6265
}
6366

6467

6568
{% endif %}
6669
</script>
6770
<!-- Twitter universal website tag code -->
6871
<script>
69-
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
70-
},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='//static.ads-twitter.com/uwt.js',
71-
a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
72+
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='//static.ads-twitter.com/uwt.js',a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
7273
// Insert Twitter Pixel ID and Standard Event data below
7374
twq('init','nv75j');
7475
twq('track','PageView');
@@ -100,13 +101,7 @@
100101
<!-- Facebook Pixel Code -->
101102
<script>
102103
!function(f,b,e,v,n,t,s)
103-
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
104-
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
105-
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
106-
n.queue=[];t=b.createElement(e);t.async=!0;
107-
t.src=v;s=b.getElementsByTagName(e)[0];
108-
s.parentNode.insertBefore(t,s)}(window,document,'script',
109-
'https://connect.facebook.net/en_US/fbevents.js');
104+
{if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window,document,'script', 'https://connect.facebook.net/en_US/fbevents.js');
110105
fbq('init', '1646638862321038');
111106
fbq('track', 'PageView');
112107
</script>

_layouts/post.html

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,86 @@
66
<div class="panel-container">
77
{% if terms > 0 %}
88
<div class="panel-left content">
9-
{% else %}
10-
<div class="content panel-singular">
11-
{% endif %}
12-
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
9+
{% else %}
10+
<div class="content panel-singular">
11+
{% endif %}
12+
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
1313

14-
<header class="post-header">
15-
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
16-
<p class="post-meta"><time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %} • <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">{{ page.author }}</span></span>{% endif %}</p>
14+
<header class="post-header">
15+
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
16+
<p class="post-meta"><time datetime="{{ page.date | date_to_xmlschema }}"
17+
itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %} •
18+
<span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">{{
19+
page.author }}</span></span>{% endif %}
20+
</p>
1721

18-
</header>
22+
</header>
1923

20-
<div class="post-content" itemprop="articleBody">
21-
{{ content }}
22-
</div>
23-
</article>
24-
{% include social-share.html %}
25-
</div>
24+
<div class="post-content" itemprop="articleBody">
25+
{{ content }}
26+
</div>
27+
</article>
28+
{% include social-share.html %}
29+
</div>
2630

27-
{% if terms > 0 %}
28-
<div class="splitter">
29-
</div>
31+
{% if terms > 0 %}
32+
<div class="splitter">
33+
</div>
3034

31-
<div class="panel-right">
32-
<span class="resize-warning">If the commandline doesn't appear in the terminal, make sure popups are enabled or try resizing the browser window.</span>
33-
{% for i in (1..terms) %}
34-
<div class="term{{i}}"></div>
35-
{% endfor %}
36-
</div>
37-
{% endif %}
35+
<div class="panel-right">
36+
<span class="resize-warning">If the commandline doesn't appear in the terminal, make sure popups are enabled
37+
or try resizing the browser window.</span>
38+
{% for i in (1..terms) %}
39+
<div class="term{{i}}"></div>
40+
{% endfor %}
41+
</div>
42+
{% endif %}
3843

39-
</div>
44+
</div>
4045

41-
<script>
42-
(function() {
43-
var font3 = document.createElement('link');
44-
font3.type = 'text/css';
45-
font3.rel = 'stylesheet';
46-
font3.href = '{{site.baseurl}}/css/syntax-highlighting.css';
47-
var q = document.getElementsByTagName('link')[0];
48-
q.parentNode.insertBefore(font3, q);
49-
})();
50-
</script>
51-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
52-
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/dist/jquery-resizable.min.js"></script>
53-
<script src="https://cdn.rawgit.com/play-with-docker/sdk/74a853bbc404ce08c091a4b2c6f1de52df0da933/dist/pwd.js"></script>
54-
<script src="{{site.baseurl}}/js/quiz.js"></script>
55-
<script>
56-
var siteUrl = "{{ site.url }}"
57-
{% if site.url == 'https://training.play-with-docker.com' %}
58-
if ((window.location.protocol + '//' + window.location.hostname) == siteUrl) {
59-
pwd.on('init', function() {
60-
pwd.getUserInfo(function(pwduser){
61-
user = pwduser;
62-
if(user !== undefined){
63-
analytics.identify(user.provider_user_id,{"email":user.email});
64-
} else {
65-
analytics.identify();
66-
}
67-
});
68-
});
69-
} else {
70-
console.log('In _config.yml, the site url does not match the url you are serving from, so no analytics were pushed.')
71-
}
72-
{% endif %}
73-
pwd.newSession([{selector: '.term1'}, {selector: '.term2'}, {selector: '.term3'}], {baseUrl: '{{site.pwdurl}}', ImageName: '{{page.image}}'});
74-
$(".panel-left").resizable({
75-
handleSelector: ".splitter",
76-
resizeHeight: false,
77-
onDragEnd: pwd.resize.bind(pwd)
78-
});
79-
window.onbeforeunload = function(e) {
80-
navigator.sendBeacon("{{site.pwdurl}}/sessions/" + pwd.sessionId + "/close");
81-
e.preventDefault();
82-
e.returnValue = 'Hi';
83-
}
46+
<script>
47+
(function () {
48+
var font3 = document.createElement('link');
49+
font3.type = 'text/css';
50+
font3.rel = 'stylesheet';
51+
font3.href = '{{site.baseurl}}/css/syntax-highlighting.css';
52+
var q = document.getElementsByTagName('link')[0];
53+
q.parentNode.insertBefore(font3, q);
54+
})();
55+
</script>
56+
<script
57+
src="https://cdn.rawgit.com/play-with-docker/sdk/74a853bbc404ce08c091a4b2c6f1de52df0da933/dist/pwd.js"></script>
58+
<script src="{{site.baseurl}}/js/quiz.js"></script>
59+
<script>
60+
addEventListener("load", (event) => {
61+
var siteUrl = "{{ site.url }}"
62+
{% if site.url == 'https://training.play-with-docker.com' %}
63+
if ((window.location.protocol + '//' + window.location.hostname) == siteUrl) {
64+
pwd.on('init', function () {
65+
pwd.getUserInfo(function (pwduser) {
66+
user = pwduser;
67+
if (user !== undefined) {
68+
analytics.identify(user.provider_user_id, { "email": user.email });
69+
} else {
70+
analytics.identify();
71+
}
72+
});
73+
});
74+
} else {
75+
console.log('In _config.yml, the site url does not match the url you are serving from, so no analytics were pushed.')
76+
}
77+
{% endif %}
78+
pwd.newSession([{ selector: '.term1' }, { selector: '.term2' }, { selector: '.term3' }], { baseUrl: '{{site.pwdurl}}', ImageName: '{{page.image}}' });
79+
$(".panel-left").resizable({
80+
handleSelector: ".splitter",
81+
resizeHeight: false,
82+
onDragEnd: pwd.resize.bind(pwd)
83+
});
84+
window.onbeforeunload = function (e) {
85+
navigator.sendBeacon("{{site.pwdurl}}/sessions/" + pwd.sessionId + "/close");
86+
e.preventDefault();
87+
e.returnValue = 'Hi';
88+
}
89+
});
8490

85-
</script>
91+
</script>

0 commit comments

Comments
 (0)