Piwik (analytics software), works by including a small script just before the </body>
:
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//piwik.example.com";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
This script will then include piwik.js
(basically this script) from your piwik installation on the page. piwik.js
records a couple of things (screen size, ip, etc.) and sends that to your piwik installation in a GET request, to register the pageview.
Now I don't understand why you would not just include piwik.js on your page straightaway. Why go through the trouble of fetching it from a separate location when you can just concatenate and minify it with the rest of your scripts?
It is possible to host piwik.js
on a cdn (see here and here), so I'm wondering why you wouldn't skip that step and concatenate it with the rest of your scripts and optimize from there?
Google analytics does the same thing I believe, so the answer doesn't need to be specific to Piwik as long as it applies to both.
` would: 1. prevent it from being loaded in parallel 2. prevent automatic version control 3. Maybe delay the recording of data. Other than that, there are no downsides? Because for me the server that serves piwik.js is the bottleneck, so I think that for me speed would improve when concatenating piwik.js with my other scripts, and I would be fine with less version control and delayed recording.
– vkjb38sjhbv98h4jgvx98hah3fef Dec 19 '14 at 13:31