A
AlexxxBcN
Gamma
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Hola , al añadir async en la libreria jquery el script que hace funcionar el menu en la version mobile me deja de funcionar
Alguna forma para que al añadir async me funcione dicho script ? Gracias.
Aclarar que esos scripts , están en el mismo codigo <script> .... </script>
Por si eso tiene que ver , y mejor estén por separado a la hora de ponerle async
Update:
Usando jquery me carga 3 script , sin añadir async me funcionan bien MIS SCRIPTS ( menu version móvil - boton subir arriba - Indice por etiquetas )
Trás muchas pruebas estos días añadiéndole código para funcionar con async ... , y viendo el funcionamiento : aveces puede que incluso me funcionen los 3 a la vez ... aveces solo 1 .. aveces 2... pero inestable , y en la consola me muestra errores
Probé varios codigos ... unos mejor que otros , algunos los entiendo otros no ....
Otra posible solución compartida por el usuario agiadas
Loading jQuery asynchronously - JavaScript - Ibrahim Diallo
Dejo aqui un código para poner async en la carga de srcripts , por si alguno le sirve o conoce el funcionamiento ...
Opción 1
<script async id="jquery" type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.js"></script>
Then I call a script using jquery :
<script type="text/javascript">
document.getElementById('jquery').addEventListener('load', function () {
App.init();
OwlCarousel.initOwlCarousel();
FancyBox.initFancybox();
StyleSwitcher.initStyleSwitcher();
});
</script>
Opción 2
<script async type="text/javascript" src="path_to_jquery" id="jquery_script_tag">
</script>
<script>
if ( !('jQuery' in window) )
{
window.jQueryQueue = [];
//define temporary jQuery function
window.jQuery = function(){
//just save function parameters to queue
jQueryQueue.push( arguments );
}
document.getElementById('jquery_script_tag').addEventListener('load', function(){
//call jQuery with parameters saved in queue, after it loaded
for ( var i in jQueryQueue )
jQuery.apply( document, jQueryQueue );
});
}
</script>
Opción 3
<script>
var async = async || [];
(function () {
var done = false;
var script = document.createElement("script"),
head = document.getElementsByTagName("head")[0] || document.documentElement;
script.src = 'jquery.js';
script.type = 'text/javascript';
script.async = true;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
done = true;
// Process async variable
while(async.length) { // there is some syncing to be done
var obj = async.shift();
if (obj[0] =="ready") {
$(obj[1]);
}else if (obj[0] =="load"){
$(window).load(obj[1]);
}
}
async = {
push: function(param){
if (param[0] =="ready") {
$(param[1]);
}else if (param[0] =="load"){
$(window).load(param[1]);
}
}
};
// End of processing
script.onload = script.onreadystatechange = null;
if (head && script.parentNode) {
head.removeChild(script);
}
}
};
head.insertBefore(script, head.firstChild);
})();
</script>
Si lo dejo así el script me funciona
<script src='//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'/>
Si lo dejo así el script deja de funcionar
<script src='//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js' async />
o
<script async='async' src='//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'/>
MIS SCRIPTS
//Scrip menu
<script>
//<![CDATA[
(function(b){var a=(function(){var p={bcClass:"sf-breadcrumb",menuClass:"sf-js-enabled" ......
//Scrip menu
//Menu Call
function menunav(b){b("#mobilenav").click(function(){b("#menunav").....
//ImagePOST
function bp_thumbnail_resize( .......
//backto top
jQuery(document).ready(function() {
var offset ......
//]]>
</script>
<a href='#' id='mobilenav'>Select Menu .......
[B//]Scrip menu[/B]
<script>
//<![CDATA[
menunav (jQuery);
//]]>
</script>
Alguna forma para que al añadir async me funcione dicho script ? Gracias.
Aclarar que esos scripts , están en el mismo codigo <script> .... </script>
Por si eso tiene que ver , y mejor estén por separado a la hora de ponerle async
Update:
Usando jquery me carga 3 script , sin añadir async me funcionan bien MIS SCRIPTS ( menu version móvil - boton subir arriba - Indice por etiquetas )
Trás muchas pruebas estos días añadiéndole código para funcionar con async ... , y viendo el funcionamiento : aveces puede que incluso me funcionen los 3 a la vez ... aveces solo 1 .. aveces 2... pero inestable , y en la consola me muestra errores
Probé varios codigos ... unos mejor que otros , algunos los entiendo otros no ....
Otra posible solución compartida por el usuario agiadas
Loading jQuery asynchronously - JavaScript - Ibrahim Diallo
Dejo aqui un código para poner async en la carga de srcripts , por si alguno le sirve o conoce el funcionamiento ...
Opción 1
<script async id="jquery" type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.js"></script>
Then I call a script using jquery :
<script type="text/javascript">
document.getElementById('jquery').addEventListener('load', function () {
App.init();
OwlCarousel.initOwlCarousel();
FancyBox.initFancybox();
StyleSwitcher.initStyleSwitcher();
});
</script>
Opción 2
<script async type="text/javascript" src="path_to_jquery" id="jquery_script_tag">
</script>
<script>
if ( !('jQuery' in window) )
{
window.jQueryQueue = [];
//define temporary jQuery function
window.jQuery = function(){
//just save function parameters to queue
jQueryQueue.push( arguments );
}
document.getElementById('jquery_script_tag').addEventListener('load', function(){
//call jQuery with parameters saved in queue, after it loaded
for ( var i in jQueryQueue )
jQuery.apply( document, jQueryQueue );
});
}
</script>
Opción 3
<script>
var async = async || [];
(function () {
var done = false;
var script = document.createElement("script"),
head = document.getElementsByTagName("head")[0] || document.documentElement;
script.src = 'jquery.js';
script.type = 'text/javascript';
script.async = true;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
done = true;
// Process async variable
while(async.length) { // there is some syncing to be done
var obj = async.shift();
if (obj[0] =="ready") {
$(obj[1]);
}else if (obj[0] =="load"){
$(window).load(obj[1]);
}
}
async = {
push: function(param){
if (param[0] =="ready") {
$(param[1]);
}else if (param[0] =="load"){
$(window).load(param[1]);
}
}
};
// End of processing
script.onload = script.onreadystatechange = null;
if (head && script.parentNode) {
head.removeChild(script);
}
}
};
head.insertBefore(script, head.firstChild);
})();
</script>
Si lo dejo así el script me funciona
<script src='//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'/>
Si lo dejo así el script deja de funcionar
<script src='//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js' async />
o
<script async='async' src='//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'/>
MIS SCRIPTS
//Scrip menu
<script>
//<![CDATA[
(function(b){var a=(function(){var p={bcClass:"sf-breadcrumb",menuClass:"sf-js-enabled" ......
//Scrip menu
//Menu Call
function menunav(b){b("#mobilenav").click(function(){b("#menunav").....
//ImagePOST
function bp_thumbnail_resize( .......
//backto top
jQuery(document).ready(function() {
var offset ......
//]]>
</script>
<a href='#' id='mobilenav'>Select Menu .......
[B//]Scrip menu[/B]
<script>
//<![CDATA[
menunav (jQuery);
//]]>
</script>
Última edición: