Ticket #2529521 (closed enhancement)

Reporter


Jeff Craig
Opened: 11/10/10
Last modified: 05/10/12
Status: closed
Type: enhancement
Resolution: fixed

Owner


Dav Glass
Target Release: 3.5.0
Priority: P3 (normal)
Summary: Consider making the presence of YUI CSS detectable by the loader
Description:

It is possible to include the CSS modules of YUI (grids, fonts, reset, etc) using loader via a 'use' statement, as was pointed out by Matt Sweeney during his YUIConf talk on YUI3 Grids. However, if
YUI3 Grids have already been loaded into the page without using YUI3 Loader, and a module requests grids to be available, it will be loaded again unnecessarily.

If a different combo URI is generated out of loader, this will result in an extra request, otherwise the browser will reprocess the CSS unnecessarily, and it could impact the cascade as well.

Type: enhancement Observed in Version: 3.3.0 PR1
Component: Loader Severity: S3 (normal)
Assigned To: Dav Glass Target Release: 3.5.0
Location: Library Code Priority: P3 (normal)
Tags: Relates To:
Browsers: All
URL:
Test Information:

<html>
<head>
<title>Loader Test regarding CSS Grids</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0pr1/build/cssgrids/grids-min.css" />
</head>
<body>
<script type="text/javascript" src="http://yui.yahooapis.com/3.3.0pr1/build/yui/yui-min.js"></script>
<script type="text/javascript">
YUI().use('cssgrids');
</script>
</body>
</html>

Change History

Adam Moore

YUI Contributor

Posted: 11/10/10
  • status changed from new to infoneeded

CSS files can't register themselves with YUI like the script files can, so there isn't a reliable way to know you pre-loaded it. But you can tell YUI that you've done so.

If you want to front load all your css, you can set 'fetchCSS' to false.

If you want to front load some of the CSS, and not the rest, you can use the 'ignore' config

ignore: ['css-fonts', ...

Does that help?

Jeff Craig

YUI Contributor

Posted: 11/11/10
  • status changed from infoneeded to assigned

This report came out of a question asked during Matt Sweeney's talk, where someone asked how, if they were making a widget that depended on Grids, how could they know if the grids was available, to which Matt replied that it could be listed as 'required' in the users 'add' statement. This is where I potentially see this actually getting triggered.

I'll be honest, I really don't have an answer, and with CSS3 grids being fairly small, it may not be worth looking at too closely, as the only way I can think to address it would be to have loader do a pattern match against the href's in the link tags in the header, or looking for yui3-g or yui3-u classes on the page. Both of these add overhead and are not necessarily reliable, though there results could be cached, so it would be a one-time check which could potentially be deferred using the conditional loading code in the loader framework.

This may well be a WONTFIX or INVALID issue, as it's hard to say if it's even likely to be triggered, or if it being triggered is a problem, I did notice that Loader won't reload CSS Grids if YUI().use('cssgrids') is executed again, so Loader already has a small amount of smarts on this, but it seemed like something that there *may* be a solution to, even if it's not something that warrants immediate attention.

Adam Moore

YUI Contributor

Posted: 11/22/10
  • owner changed from Adam Moore to Matt Sweeney
  • summary changed from Loader doesn't check for CSS Modules to Consider making the presence of YUI CSS detectable by the loader

As things are now, there isn't a good way to know what YUI CSS is on the page. Normally this isn't a huge hurdle, but if we want to try to do something about it we could consider adding a convention to the css that would be detectable by the loader.

Matt Sweeney

YUI Developer

Posted: 12/2/10
  • milestone changed to 3.NEXT
  • status changed from assigned to accepted

George

YUI Developer

Posted: 04/20/11

Dav Glass

Posted: 04/26/11
  • status changed from assigned to accepted
  • type changed from defect to enhancement

I have considered testing "fake" properties in the CSS build file's to determine if they loaded..

Something like this at the bottom of the grids file (generated by builder):

body {
yui3-cssgrids: 'loaded';
}

Note: I haven't tested this and I'm not sure if it would even work.

Dav Glass

Posted: 11/8/11
  • milestone changed from 3.NEXT to 3.5.0

Dav Glass

Posted: 11/8/11
  • estimated changed from 0 to 0.75
  • remaining changed from 0 to 0.75
  • sprint changed to sprint 1

Matt Sweeney and I discussed this at YUIConf last week and came up with this prototype:

When YUI stamps the page, it creates an element called #yui-css-enabler
Then the builder stamps all CSS files with this at the end: #yui-css-enabler.MODULE_NAME { font-weight: bold; /* Or another property */}

Then Loader can add the class to the element and check if the style is applied. If it is, the CSS file is loaded, if it is not, load it..

Dav Glass

Posted: 12/1/11

Pull request for this code: https://github.com/yui/yui3/pull/56

Dav Glass

Posted: 12/2/11
  • completed changed from 0 to 0.75
  • remaining changed from 0.75 to 0
  • status changed from accepted to checkedin

Dav Glass

Posted: 12/2/11
  • resolution changed to fixed

Fixes #2529521 - Added CSS Stamp detection for pre-loaded CSS files.
View Commit: 7128e1d29f3b88ea3ea918b0a71359c39183c69f

Dav Glass

Posted: 12/6/11

Fixes #2529521 - Added CSS Stamp detection for pre-loaded CSS files.
View Commit: 7128e1d29f3b88ea3ea918b0a71359c39183c69f

Jenny Donnelly

YUI Developer

Posted: 05/10/12
  • status changed from checkedin to closed

checkedin -> closed