Tansel Yuzer

How to change js in order ot make it asyn and defered for SEO

4 posts in this topic

Hello,

Google and GTMetrix complain about twitter script is not async.


The following resources are loaded synchronously. Load them asynchronously to reduce blocking of page rendering.
http://smartsailing.org/ loads http://platform.twitter.com/widgets.js synchronously.
[/CODE]

So how can we make it async and defered, so that page loading time is not effected by slow twitter connections.

Thanks

Share this post


Link to post
Share on other sites

Hi there.

The script file is define in your embed code.

For example

<a class="twitter-timeline" href="https://twitter.com/BoulevardResTea" data-widget-id="486152071125549056">Tweets by @BoulevardResTea</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>[/CODE]

You can see

js.src = p + "://platform.twitter.com/widgets.js";

Please try to change it to

js.src = p + "://yourdomain/widgets.js";

Then download this file http://platform.twitter.com/widgets.js and copy it to your joomla root folder.

I hope it will help you.

Share this post


Link to post
Share on other sites

I actually used another version I found from twitter web site for this purpose. Maybe I can combine your sugegstion with this async version.


<a class="twitter-timeline" href="https://twitter.com/SmartSailingAca" data-widget-id="583258451108823040">Tweets by @SmartSailingAca</a><script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);

t._e = [];
t.ready = function(f) {
t._e.push(f);
};

return t;
}(document, "script", "twitter-wjs"));</script>
[/CODE]

Share this post


Link to post
Share on other sites

Hi.

you can try this solution

Open file plugins/content/bt_socialshare/bt_socialshare.php

Find this function

public function getTwitterButton($link_article, $langTagArr)

Change it to


public function getTwitterButton($link_article, $langTagArr) {
$html = '
<a class="twitter-timeline" href="https://twitter.com/SmartSailingAca" data-widget-id="583258451108823040">Tweets by @SmartSailingAca</a><script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);

t._e = [];
t.ready = function(f) {
t._e.push(f);
};

return t;
}(document, "script", "twitter-wjs"));</script>
';
return array($html, '');
}
[/CODE]

Good luck.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now