Skip to content

Commit 2e69c76

Browse files
committed
加载优化,ref #136
1 parent 7d64afb commit 2e69c76

File tree

11 files changed

+44
-47
lines changed

11 files changed

+44
-47
lines changed

layout/_partial/google-analytics.ejs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<% if (theme.google_analytics){ %>
22
<!-- Google Analytics -->
33
<script>
4-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
5-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
6-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
7-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
8-
9-
ga('create', '<%= theme.google_analytics %>', 'auto');
4+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
5+
ga('create', '<%- theme.google_analytics %>', 'auto');
106
ga('send', 'pageview');
11-
127
</script>
8+
<script async src='https://www.google-analytics.com/analytics.js'></script>
139
<!-- End Google Analytics -->
1410
<% } %>

layout/_partial/head.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@
4646
<% } %>
4747
<%- favicon_tag(theme.favicon) %>
4848
<link rel="stylesheet" href="<%= url_for('/css/style.css?v='+ theme_version()) %>">
49+
<script>window.lazyScripts=[]</script>
50+
<%- partial('google-analytics') %>
4951
</head>

layout/_partial/mathjax.ejs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<% if (theme.mathjax){ %>
12
<!-- mathjax config similar to math.stackexchange -->
23
34
<script type="text/x-mathjax-config">
@@ -12,9 +13,10 @@ MathJax.Hub.Config({
1213
MathJax.Hub.Queue(function() {
1314
var all = MathJax.Hub.getAllJax(), i;
1415
for(i=0; i < all.length; i += 1) {
15-
all[i].SourceElement().parentNode.className += ' has-jax';
16-
}
16+
all[i].SourceElement().parentNode.className += ' has-jax';
17+
}
1718
});
1819
</script>
1920
20-
<script type="text/javascript" async src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
21+
<script async src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
22+
<% } %>

layout/_partial/post/comment.ejs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88

99
<% if (post.comments && theme.disqus_shortname){ %>
1010
<section id="comments">
11-
<div id="disqus_thread"></div>
12-
<script type="text/javascript">
13-
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
14-
var disqus_shortname = '<%=theme.disqus_shortname%>'; // required: replace example with your forum shortname
15-
16-
/* * * DON'T EDIT BELOW THIS LINE * * */
17-
(function() {
18-
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
19-
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
20-
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
21-
})();
22-
</script>
23-
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
11+
<div id="disqus_thread"></div>
12+
<script>
13+
var disqus_shortname = '<%- theme.disqus_shortname %>';
14+
lazyScripts.push('//' + disqus_shortname + '.disqus.com/embed.js')
15+
</script>
16+
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
2417
</section>
2518
<% } %>

layout/_partial/post/duoshuo.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="duoshuo" id="comments">
22
<div class="ds-thread" data-thread-key="<%=key%>" data-title="<%=title%>" data-url="<%=url.replace(/index\.html$/, '')%>"></div>
33
</div>
4-
<script src="<%= url_for('/js/embed' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>"></script>
5-
<script src="//cdn.bootcss.com/marked/0.3.6/marked.min.js" async="async"></script>
4+
<script src="<%- url_for('/js/embed' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>" async></script>
65
<script>
76
var duoshuoQuery = {short_name:'<%=theme.duoshuo %>', theme: 'none'}
7+
lazyScripts.push('//cdn.bootcss.com/marked/0.3.6/marked.min.js')
88
</script>

layout/_partial/post/share.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%
22
// 使用 sns 直接分享接口
3-
// 微信使用 http://s.jiathis.com/qrcode.php?url=xxx
3+
// 微信使用 qrcode helper 或 http://goqr.me/api/ 生成二维码
44
var sUrl = url.replace(/index\.html$/, '')
55
var sTitle = page.title ? ''+ page.title +'》 — ' + config.title : config.title
66
var sDesc = truncate(strip_html(page.excerpt || config.description), { length: 80})
@@ -49,6 +49,6 @@
4949
<div class="page-modal wx-share" id="wxShare">
5050
<a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
5151
<p>扫一扫,分享到微信</p>
52-
<img src="<%- 'qrcode' in locals ? qrcode(sUrl) : 'http://s.jiathis.com/qrcode.php?url=' + sUrl %>" alt="微信分享二维码">
52+
<img src="<%- 'qrcode' in locals ? qrcode(sUrl) : '//api.qrserver.com/v1/create-qr-code/?data=' + sUrl %>" alt="微信分享二维码">
5353
</div>
5454
<% } %>

layout/_partial/script.ejs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
2-
<script src="<%= url_for('/js/main' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>"></script>
32

4-
<% if (theme.search){ %>
5-
<%- partial('search') %>
6-
<script src="<%= url_for('/js/search' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>"></script>
7-
<% } %>
8-
9-
<% if (theme.mathjax){ %>
103
<%- partial('mathjax') %>
11-
<% } %>
124

135
<% if (theme.cnzz){ %>
14-
<script src="//s95.cnzz.com/z_stat.php?id=<%=theme.cnzz %>&web_id=<%=theme.cnzz %>"></script>
6+
<script>lazyScripts.push('//s95.cnzz.com/z_stat.php?id=<%-theme.cnzz %>&web_id=<%-theme.cnzz %>')</script>
157
<% } %>
168

17-
<%- partial('google-analytics') %>
9+
<script src="<%- url_for('/js/main' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>"></script>
10+
11+
<% if (theme.search){ %>
12+
<%- partial('search') %>
13+
<script src="<%- url_for('/js/search' + (cache ? '.min': '') + '.js?v=' + theme_version()) %>" async></script>
14+
<% } %>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-theme-material-indigo",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Material Design theme for Hexo.",
55
"keywords": [
66
"hexo",

source/css/_partial/fontawesome.less

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
padding-right: 5px;
5656
}
5757

58-
/* Font Awesome uses the Unicode Private Use Area (PUA) to ensure screen
59-
readers do not read off random characters that represent icons */
60-
6158
@fa-var-500px: "\f26e";
6259
@fa-var-address-book: "\f2b9";
6360
@fa-var-address-book-o: "\f2ba";

source/js/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@
403403
forEach.call($$('.img-lightbox'), function (el) {
404404
new LightBox(el)
405405
})
406-
})()
406+
})(),
407+
loadScript: function (scripts) {
408+
body.insertAdjacentHTML('beforeend', scripts.map(function (src) {
409+
return '<script async src="' + src + '"></script>'
410+
}).join(''))
411+
}
407412
};
408413

409414
w.addEventListener('load', function () {
@@ -414,6 +419,8 @@
414419
Blog.toc.actived(top);
415420
loading.classList.remove('active');
416421
Blog.page.loaded();
422+
423+
w.lazyScripts && w.lazyScripts.length && Blog.loadScript(w.lazyScripts)
417424
});
418425

419426
var ignoreUnload = false;
@@ -482,8 +489,11 @@
482489
return g
483490
}, w.BLOG);
484491

485-
Waves.init();
486-
Waves.attach('.global-share li', ['waves-block']);
487-
Waves.attach('.article-tag-list-link, #page-nav a, #page-nav span', ['waves-button']);
488-
492+
if (w.Waves) {
493+
Waves.init();
494+
Waves.attach('.global-share li', ['waves-block']);
495+
Waves.attach('.article-tag-list-link, #page-nav a, #page-nav span', ['waves-button']);
496+
} else {
497+
console.error('Waves loading failed.')
498+
}
489499
})(window, document);

0 commit comments

Comments
 (0)