Skip to content

Commit

Permalink
Optimized disqus load
Browse files Browse the repository at this point in the history
  • Loading branch information
axsapronov committed May 17, 2016
1 parent 7308538 commit d5b7694
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
6 changes: 6 additions & 0 deletions digest/templates/digest/pages/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ <h2>{{ data.grouper.title }}</h2></a>


{% endblock %}


{% block scripts %}
{{ block.super }}
{% include 'blocks/_disqus_script.html' %}
{% endblock %}
5 changes: 5 additions & 0 deletions digest/templates/digest/pages/news_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@
{% endblock %}


{% block scripts %}
{{ block.super }}
{% include 'blocks/_disqus_script.html' %}
{% endblock %}



27 changes: 6 additions & 21 deletions templates/blocks/_disqus.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
<div class="row">
<div class="comments-container">
<button
class="show-comments btn btn-success btn-large">
Load Disqus comments
</button>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'pythondigest'; // required: replace example with your forum shortname
{% if identifier %}
var disqus_identifier = '{{ identifier }}';
{% endif %}

/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a
href="http://disqus.com/?ref_noscript">comments powered by
Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span
class="logo-disqus">Disqus</span></a>
</div>
</div>


21 changes: 21 additions & 0 deletions templates/blocks/_disqus_script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script type="text/javascript">
$(document).ready(function () {
$('.show-comments').on('click', function () {
var disqus_shortname = 'pythondigest'; // required: replace example with your forum shortname
{% if identifier %}
var disqus_identifier = '{{ identifier }}';
{% endif %}

// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
cache: true
});
// hide the button once comments load
$(this).fadeOut();
});
});
</script>
<noscript>Please enable JavaScript to view comments</noscript>

0 comments on commit d5b7694

Please sign in to comment.