Giter VIP home page Giter VIP logo

webfonts-subsetting's Introduction

webfonts-subsetting

Tailor / Subsetting font files for web page automatically. The subsetted font will be used for webfonts service, and only contains characters used in that page.
It's useful for those languages with massive glyphs, such as Chinese Hanzi.

Usage

As shown in /example:

  1. Include jQuery in the page
  2. Change the configurations at the begining of /src/webfonts.subsetting.js, and include it in the page
  3. Change the configurations at the begining of /src/webfonts_subsetting.php and deploy it on a php server, whose url must be the one you specified in webfonts.subsetting.js:SUBSETTING_URL.
  4. Configure the web server

Install fontforge, which will be used in subsetting
Make sure the php can execute fix_ttf.pe
Make sure the php has WRITE access to the font directory
Make sure the php has WRITE access to its own directory if you want to see logs

If every thing goes well, you'll see some subsetted font files in the fonts directory, and a <style> element of font-faces is added at the ending of <head>.
Or you can check the logs ( fix_ttf.out, mv_ttf.out ) beside webfonts_subsetting.php to find what happened.

Online Examples

Goto online example hosted on Wiki Media Fundation Labs
Goto example integrated into mediawiki

Better Integration

I implement this as simple as possible, to make it extensible for different scenarios. Maybe you need some ideas about how to integrate it better.

  1. Cache. Subsetting is a time-consuming work, so you'd better cache the subsetted fonts. And during the subsetting request, send a hash first to expect cache-hitting, while not send the huge set of characters sequence.
  2. Lock. Conflicts may happen when multiple requests for the same subsetting job reach at the same time, so you'd better have a lock when you doing subsetting for each subset.

webfonts-subsetting's People

Contributors

xiaoxq avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.