Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
¿Cómo cargar CSS de forma asíncrona usando jQuery?

Quiero usar jQuery para cargar CSS de forma asíncrona para un documento.

Encontré esta muestra, pero esto no parece funcionar en IE:

 <script type="text/javascript" src="/inc/body/jquery/js/jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(function(){ $('<link>', { rel: 'stylesheet', type: 'text/css', href: '/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css' }).appendTo('head'); $.getScript("/inc/body/jquery/js/jquery-ui-1.8.10.custom.min.js", function(){ }); }); </script>

Básicamente, quiero cargar jQuery UI después de que todos los demás datos, imágenes, estilos, etc. se carguen en la página.

El $.getScript funciona muy bien para el archivo JS. El único problema es con CSS en IE.

¿Conoces una solución mejor?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Aquí hay un método para la carga asincrónica de hojas de estilo que no bloquea el procesamiento de la página que funcionó para mí:

https://github.com/filamentgroup/loadCSS/blob/master/loadCSS.js

Ejemplo reducido del código vinculado anteriormente, basado en la respuesta de lonesomeday

 var stylesheet = document.createElement('link'); stylesheet.href = '/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css'; stylesheet.rel = 'stylesheet'; stylesheet.type = 'text/css'; // temporarily set media to something inapplicable to ensure it'll fetch without blocking render stylesheet.media = 'only x'; // set the media back when the stylesheet loads stylesheet.onload = function() {stylesheet.media = 'all'} document.getElementsByTagName('head')[0].appendChild(stylesheet);
over 4 years ago · Santiago Trujillo Report

0

La forma segura es la forma antigua...

 var stylesheet = document.createElement('link'); stylesheet.href = '/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css'; stylesheet.rel = 'stylesheet'; stylesheet.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(stylesheet);
over 4 years ago · Santiago Trujillo Report

0

Esto debería funcionar en IE:

 $("head").append("<link rel='stylesheet' type='text/css' href='/inc/body/jquery/css/start/jquery-ui-1.8.10.custom.css' />");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!