Reputation: 6053
We have a public website. It contains the Facebook Pixel script. However, in our region sometimes the speed to the Facebook drops down dramatically whereas the rest of the Internet works fine. When it happens the main page loads very slowly. This is the script located in the head of the page:
<script>
!function(f,b,e,v,n,t,s)
{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');
fbq('init', '123456');
fbq('track', 'PageView');
</script>
As far as I know this script should load asynchronously but it seems that is doesn't, because the page cannot render completely until the facebook pixel finishes its work. I even set the pagespeed EnableFilters defer_javascript
in the pagespeed module of my nginx but it doesn't help.
What can I do? What am I doing wrong?
Upvotes: 1
Views: 2387
Reputation: 1068
You can try adding to the script tag itself to deferscript
<script defer>
You could try async
, but I'm sure it doesn't work on the inline script. If you're pulling in the facebook javascript file, then you could async that too.
<script async>
This way, you won't need pagespeed to do the deferring
Upvotes: 2