Can we move only selected css to footer without javascript?
If we use JavaScript for all css, we see delay.

Comments

anikitin35 created an issue. See original summary.

mikeytown2’s picture

Title: Move selected css to footer » Move selected css to footer; make first css file blocking if using loadCSS
Version: 7.x-2.17 » 7.x-2.x-dev
Assigned: anikitin35 » Unassigned

Looks like this is technically possible
http://stackoverflow.com/questions/4957446/load-external-css-file-in-bod...
http://stackoverflow.com/questions/8033622/css-stylesheets-at-top-or-bot...

Noted that advagg uses filamentgroup/loadCSS
https://gist.github.com/scottjehl/87176715419617ae6994

You want to inline the critical css https://www.fourkitchens.com/blog/article/use-grunt-and-advagg-inline-cr.... Another option I've been thinking of is to make the first css file blocking.

mikeytown2’s picture

Status: Active » Needs review
StatusFileSize
new5.87 KB

Makes loadCSS usable on any site now.

mikeytown2’s picture

Title: Move selected css to footer; make first css file blocking if using loadCSS » make first css file blocking if using loadCSS or first 12kb of data inline.

Just tried setting a cookie to get around the jarring effect that happens when using defer so it doesn't defer on second load but that doesn't work. Going to go with just this.

This works but the browser still ends up downloading the JS first.

if (document.cookie.match(/^.*?advaggmod_css=1.*?$/)) {
  var sheets = document.querySelectorAll('link[rel=preload]');
  for (i = 0; i < sheets.length; ++i) {
    sheets[i].setAttribute('rel', 'stylesheet');
    sheets[i].removeAttribute('onload');
    sheets[i].removeAttribute('as');
  }
}
else {
  window.onload = function() {
    document.cookie = 'advaggmod_css=1'
      + '; expires=' + new Date(new Date().getTime() + 86400 * 1000).toUTCString()
      + '; domain=.' + document.location.hostname
      + '; path=/';
  };
}

  • mikeytown2 committed 541dffb on 7.x-2.x
    Issue #2646684 by mikeytown2: make first css file blocking if using...
mikeytown2’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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