documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Font Squirrel embeds .woff fonts... #90

Closed agibralter closed 13 years ago

agibralter commented 13 years ago

Should Jammit do that too?

joecorcoran commented 13 years ago

You can embed woff font files as of 0.5.3 according to the change log -- I can confirm that it works. You get a warning in the Chrome console about the mime type, but since there doesn't appear to be a standard mime type for woff yet, "font/woff" will have to do.

agibralter commented 13 years ago

Ahh ok I see what's going on. So first, I tried to use FontSquirrel's font generator with the pre-embedded woff and ttf fonts, but it was causing YUI-compressor to freeze when it encountered the long datauris. I decided to use FontSquirrel's font generator without the pre-embedded fonts and leave the embedding to Jammit. I noticed that Jammit wasn't embedding one of the woffs (for DroidSans) but it was embedding the woff for ChunkFive.

Jammit enforces the 32kb limit for embedding woff fonts, but FontSquirrel doesn't... I guess that should have been my original issue subject...

woff is included in EMBED_MIME_TYPES but it is missing from EMBED_FONTS...

def embeddable?(asset_path, variant)
  font = EMBED_FONTS.include?(asset_path.extname)
  return false unless variant
  return false unless asset_path.to_s.match(EMBEDDABLE) && asset_path.exist?
  return false unless EMBED_EXTS.include?(asset_path.extname)
  # this is returning false for woff > 32kb
  return false unless font || encoded_contents(asset_path).length < MAX_IMAGE_SIZE
  return false if font && variant == :mhtml
  return true
end
joecorcoran commented 13 years ago

That's interesting -- the woff I'm embedding is 16 KB and only has A-Za-z0-9 glyphs. So does that mean it's fairly plausible that a lot of woff files will exceed 32 KB?

jashkenas commented 13 years ago

This is just an oversight, and here's the patch:

https://github.com/documentcloud/jammit/commit/1d1ac8ebd6e34da46cf7fba2e43228fc1d49b8d5

The 32kb limit is just for images in IE -- fonts don't apply. Many fonts are larger than 32kb in size, and you still want to embed them, in order to avoid the flash of unstyled content.

Closing the ticket.