arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

New parameter asyncdef #112

Closed arvgta closed 7 years ago

arvgta commented 7 years ago

EDIT: Default value of false presumed to be correct - please re-open, if you disagree


This is about external scripts, dynamically loaded by Ajaxify only:

Here's what the default value of async is in a non-ajaxified environment. I would like to emulate the same effect in an ajaxified environment.

This new parameter specifies, what the default value for async for external files is, if nothing is specified in the source:

asyncdef: false //default - synchronous load, like the browsers treats non-ajax pages
asyncdef: true // asynchronous loading

Do you agree with the default value being false i.e. synchronous? (if async is specified, Ajaxify sets the value to true)


Current code

iScript: function ($S, aSync) { //insert single script - pre-processing
    if(!aSync) aSync = asyncdef; //aSync not given -> load default (asyncdef)
    else aSync = true; //otherwise set aSync to true

    if($S instanceof jQuery) return $.scripts($S); //insert single inline script
    var tag = $((PK == "href" ? linki : scri).replace("*", $S)); //generate tag for external script (stylesheet or external JS)
    if(PK != "href") tag.async = aSync; //set async for external JS scripts
    $("head").append(tag); //insert single external script - append to head
},

Demo

or this

German site