Script "https://script.ioam.de/iam.js" is not loaded asynchronously. This is additionally reported by sitespeedio as SPOF (single point of failure):

The page has 1 requests inside of the head that can cause a SPOF (single point of failure). Load them asynchronously or move them outside of the document head.
https://script.ioam.de/iam.js

Would be cool it load asynchronously to prevent SPOF and make site performance better. I believe this won't break any of the features the script is providing.

Comments

hideaway created an issue. See original summary.

hideaway’s picture

StatusFileSize
new396 bytes

The following patch should do the trick

pagach’s picture

Version: 8.x-1.3 » 8.x-1.6
StatusFileSize
new500 bytes

Since defer provides better performance, here's a patch using defer tag.

Andre-B’s picture

only setting the ivw script to defer mode seems not to be sufficient for a working tracking setup.

ivw module places a block containing the targeting data like the following example

<div id="block-ivwcall">
<script type="text/javascript">
    var iam_data = {
        "st": "YYY",
        "cp": "XXX",
        "sv": "in",
        "co": "",
        "sc": "yes"
    };

    if ( (window.innerWidth < 680) || (/iPhone/.test(window.navigator.userAgent))) {
        iam_data.cp = "XXX";
        iam_data.sv = "mo";

        var ivw_mobile_site = "mobplatzhalter";
        if((typeof ivw_mobile_site !== 'undefined') && ivw_mobile_site != '') {
            iam_data.st = ivw_mobile_site;
        }
    }
    if ((typeof window.iom !== 'undefined') && (typeof window.iom.c === 'function')) {
        iom.c(iam_data, 1);
    }
</script>
</div>

tracking is only done when window.iom is specified, which will be set by the js file being loaded, since that file loading will be defered and there's no wrapper around our tracking js iom.c(iam_data, 1);, it simply won't be executed - not even an error will be produced since it's nicely wrapped.

to fix this the ivw_block js should be wrapped with a event listener to only execute after window load event has been fired.

document.addEventListener("DOMContentLoaded", function(event) {
    //document is fully loaded
    if ((typeof window.iom !== 'undefined') && (typeof window.iom.c === 'function')) {
        iom.c(iam_data, 1);
    }
});

for reference: https://stackoverflow.com/questions/42950574/are-deferred-scripts-execut...

the file to be updated for this is templates/ivw-call.twig

Andre-B’s picture

it also might be a good idea to make this as an optional configuration. so a site builder can decide whether to use the defered method or inline tracking (since it might result in a small change in stats reported). Although in my humble opinion if a visitor exits your site before the site has been loaded it's should not be tracked in the first place.

jjchinquist’s picture

Sounds reasonable, patch created to:

  1. Make "defer" or "async" or "nothing" a radio button option for site builds on the form page and update the JS accordingly.
  2. Add the dom event listener

The issue is with testing the various options, and is defer/async/nothing overkill?

Andre-B’s picture

I don't think we should be using async since we can not predict when that's finished and we rely on data being inline injected for ivw. so defer / nothing will be the only options here. if defer is selected dom event listener wrapping is required. if nothing is selected dom event listener shall not be used.

with these two options I do not think it's overkill, because this is an external asset being called on every page load, slowing down page loading for every request.

in order to not break backwards compatibility default should be nothing.

jjchinquist’s picture

Guess I have to clarify, I imagined having all options "defer/async/nothing" being an overkill for the site builder. Andre, your 2-option solution sounds more reasonable and testable.

aludescher’s picture

StatusFileSize
new8.19 KB

This patch adds a checkbox for deferred script loading and uses 'DOMContentLoaded' event when deferred loading is enabled.

avpaderno’s picture

Version: 8.x-1.6 » 8.x-1.x-dev
Issue tags: -site performance, -spof +Performance
lucastockmann’s picture

Reroll against 8.x-2.4-beta1

daniel.bosen’s picture

Reroll against 8.x-2.4-beta5

daniel.bosen’s picture

Status: Active » Reviewed & tested by the community

looks good

  • daniel.bosen committed 40a8f18 on 8.x-2.x
    Issue #3006577 by hideaway, daniel.bosen, aludescher, pagach,...
daniel.bosen’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.