question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaterialIcon component should not load the material icon font (blocks page load)

See original GitHub issue

Hello, I’m using the code in an app and totally enjoying the library:

about app

  • Static site
  • Hosted on firebase
  • Bundled/transpiled with webpack/babel-loader
  • Bundled using webpack rules to import SCSS directly from node_modules/@material/*

issue: slow rendering (fonts)

I noticed this when I ran Lighthouse (with emoji commentary) 😑 Opportunities  image

 🤔 ok cool, go find in devtools…  image

🤔 ok, go to bundle…

found this CSS import in https://github.com/material-components/material-components-web-react/tree/master/packages/material-icon: @import url(https://fonts.googleapis.com/icon?family=Material+Icons);

🤔 ok, go get that resource in chrome…

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/materialicons/v38/flUhRq6tzZclQEJ-Vdg-IuiaDsNa.woff) format('woff');
}

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
}

💪 ok cool, MaterialIcon has sass with this fonts.gstatic.com URL.

Basically any of these fonts in css files that are in HEAD will block rendering on the network if the user puts a link to the css file in head or in a style tag.

So I pre-loaded https://fonts.googleapis.com/icon?family=Material+Icons in the head of my HTML, and could preload the woff file also, but that is not really a stable way to go about it since any of the packages in the chain could break without warning.

try to fix issue

I was able to configure webpack to consume the @ material sass directly, but because of this URL I don’t know how to make this code lighthouse-friendly without putting it after the body. I may be doing something wrong at a higher level.

solution?

TL;DR: Could we come up with a way to bundle in the font resources? Or SVGs? Maybe that takes the form of documentation or an example.

My sense is that some users are going to write this off as being slow rather than tear in to the details, so if we could make stuff ‘just work’ as they say, it’d be great. Surely for places like the Top Navbar in-line SVGs would be more performant than an icon font. (I think it’s ~62kb) Maybe I don’t know about a bundler that would let me resolve this, the closest thing I found was https://www.npmjs.com/package/google-fonts-plugin, but I don’t know how I’d connect it to this code as a user.

Where’d I go wrong here? Is there something on the roadmap that I’d want to know about?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
johnelliottcommented, Jul 21, 2018

Nice work 😃 I am looking forward to using the lib more.

1reaction
lynnmerciercommented, Jul 18, 2018

When we update the MaterialIcon code so it does not download the material icon font…we should also provide documentation to our users on how to lazy load the material icon font.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material icons not working - Stack Overflow
Load the icon font in your index.html : <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">.
Read more >
React Material Icon - npm
Importing Icons. The React material icon package does not come packaged with Google Font's Material Icons. If it was included in the Sass ......
Read more >
Display of pages | Firefox Support Forum - Mozilla Support
Hi Peter, that problem is caused by the iconic Google font "Material Icons" not loading, so alternate text is displaying instead.
Read more >
Icon | Angular Material
This directive supports both icon fonts and SVG icons, but not bitmap-based ... (You will still need to include the HTML to load...
Read more >
How to use mat-icon in angular? - GeeksforGeeks
font library is loaded prior to using mat-icons-->. < link href = "https://fonts.googleapis.com/icon?family=Material+Icons&display=block".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found