Is it possible to load the script async?

Status
Not open for further replies.
#1
When I run Google PageSpeeds Insights it says the Statcounter script is blocking the rendering of the page and I should defer the loading of the script or I should load the script async.
Is there a way I can defer the loading of the script or to load the script async?
Thanks in advance
 
#2
Ues the script at the bottom of the body, just before the </body> tag. It will load dead last and not hold anything back.
As a bonus you get the most complete stats ondownloads and outgoing links that way.
 
#3
#4
I don't know what make a script asynchronous - is it just the use of "async" in the script tag? Then you can try it.
 

Rory_A

Administrator
Staff member
#6
Very sorry for the confusion. This is actually something we've been working on. So far this test script has been working ok. The only catch here is the counter has to be invisible.

Please try this code but do note you have to use your project id and security code.

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=0000000;
var sc_invisible=1;
var sc_security="AAAAAA";
</script>
<script type="text/javascript" async
src="http://www.statcounter.com/counter/counter.js"></script>
<noscript><div class="statcounter"><a title="hits counter"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/000000/0/AAAAAAA/1/"
alt="hits counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->

To see your project id and security code please try these steps.

- login to statcounter.com
- click on the wrench to the far right of the project name
- click the Security Code link in the left menu (about 1/2 way down)

Please let us know if there is any trouble.
 
Last edited by a moderator:
#8
Rory let me ask a question, if I have two projects on the same page do I need the line...

<script type="text/javascript" async src="http://www.statcounter.com/counter/counter.js"></script>

Twice? Or am I overkilling?
 
Last edited by a moderator:
#9
Dear Rory,
I've used the script that you've provided and it seems to work like a charm.
Back at 96/100 at PageSpeed.
Thank you very much.
 

Rory_A

Administrator
Staff member
#10
Rory let me ask a question, if I have two projects on the same page do I need the line...

<script type="text/javascript" async src="http://www.statcounter.com/counter/counter.js"></script>

Twice? Or am I overkilling?
Ideally there should only be one project. I'm unsure of the effects here because this setup is pretty new and I don't have a lot of experience with it - sorry! Running two projects on one page tends to cause one of them to count a little lower.

Hope that helps!
 
Last edited by a moderator:
Status
Not open for further replies.
Top