Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

FEATURE REQUEST: Manually specify the name, path to font files, and formats, and WebFont picks the best font file to load... #9

Closed
TooTallNate opened this Issue · 7 comments

3 participants

@TooTallNate

So the Custom module is close to what I need, but not quite there. I'd like a module where the CSS sheet isn't external, but dynamically created and appended to the document via JavaScript. In the end, I'm hoping for an API similar to this:

WebFont.load({
  manual: {
    name: "Arial",
    path: "./fonts/Arial",
    formats: ['woff', 'ttf', 'eot']
  }
});

Where the files were available relative to the document root at:

./fonts/Arial.woff
./fonts/Arial.ttf
./fonts/Arial.eof

WebFontLoader would have to know which types the current User-Agent supports and picks the best one to load by dynamically creating a <style> node appropriately formatted.

Any thoughts? Thanks in advance!

@rcarver
Owner

That's an interesting idea. My first thought is that it would require a decent amount of code, thus increasing the side of the library quite a bit.

But, I'd love to see what it looks like - since modules can be added to WebFont Loader at runtime, you don't even need to modify the WebFont Loader code to try it out. Check out the source for a module, like the custom module

New modules are added with:

WebFont.addModule(...)

@TooTallNate

Well for what it's worth, I've forked and made a preliminary version of how I think this manual module should work:

http://github.com/TooTallNate/webfontloader/compare/manual

As far as it requiring a large amount of code, the majority would be with inspecting the userAgent value, which this lib already has code to take care of and I'm in fact utilizing. The changes made in my commit are actually quite minimal to the library itself.

It's probably pretty fragile at the moment, as I've only been doing testing on OSX so far, but I'll do some more testing soon.

@TooTallNate

I've managed to do some cross-browser testing and got it working on Internet Explorer now, completing the A-Grade browser support. So this module is starting to feel pretty complete, and is probably ready for a pull if you guys are interested (I hope you are!). Thanks in advance!

@TooTallNate

The beauty of the WebFont#addModule function is that it can be called in an external JS file! Yay! So here's this manual module packaged up as an external module in case you guys would rather not pull to the master / until you do:

http://gist.github.com/498822

@rcarver
Owner

That's awesome! I'm very interested in how people would like to work with WFL - do you want the version hosted by Google to grow with every possible module? Or should it have only the minimum? What's the best way to let you build a custom version of WFL with just the modules you need?

(fyi, the code is released as a rubygem which makes some of this a little more possible)

Ideas welcome!

@TooTallNate

Well I don't know how much flexibility the Google hosting has (i.e. can only serve static files or can also include server-side logic), but I think it would be cool if a specially constructed URL determined which (additional) modules would be included.

Perhaps:

http://ajax.googleapis.com/ajax/libs/webfont/1.0.6/webfont.js

would only include 1 or 2 default ones (Google and TypeKit probably). But you could offer additional modules that could be compiled in dynamically through the Google server:

http://ajax.googleapis.com/ajax/libs/webfont/1.0.6/webfont.js?modules=manual,custom,ascender

That would rock IMO.

And also FWIW, I DO LIKE the idea of Google hosting pages to help with caching etc. and I DON'T LIKE the idea of hosting my own, modified version. I DON'T MIND the compromise of having Google host the untouched version and having my users download a tiny module for the loader, but in the end I'd LOVE to be able to specify a specially crafted URL that would allow Google to also cache MY code as part of the library that way.

@rcarver
Owner

Thanks Nate, I agree that would be ideal.

Jeremie, can you speak to what it would take to get WebFont Loader into the Google api's so we could compile it at runtime?

@bramstein bramstein closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.