When connection to facebook is slowed down the site loads slowly
When connection to facebook is slowed down the site loads slowly
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:
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.
pagespeed EnableFilters defer_javascript
What can I do? What am I doing wrong?
<script async>
src
“What can I do? What am I doing wrong?” - probably nothing, and probably nothing. You might just have to decide whether sniffing on users all the time is actually more important to you in the end, than overall good performance of your site … :-)
– CBroe
Jun 29 at 11:07
@CBroe, even
defer
and async
tags won't help me?– Nurjan
Jun 29 at 11:14
defer
async
This code is already written to load the SDK asynchronously, and the script element it dynamically creates and inserts into the document to load the external resource already has the
async
flag set (t.async=!0;
) “This is the script located in the head of the page” - putting it at the end of body is the only thing I can think of that could possibly further improve performance.– CBroe
Jun 29 at 11:19
async
t.async=!0;
1 Answer
1
You can try adding to the script tag itself to deferscript
<script defer>
<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.
async
<script async>
<script async>
This way, you won't need pagespeed to do the deferring
Thanks for your answer I will check your solution and write to you back.
– Nurjan
Jun 29 at 11:14
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try adding
<script async>
in your tag. P.S only works on external scripts usingsrc
.– Alex
Jun 29 at 11:02