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.

For anyone wanting to avoid loading several hundred pngs, here's the trick

See original GitHub issue

By default emojione loads a small png for each emoji, but there’s a spritesheet option that loads only one image then renders via background-position for each emoji.

It’s simple to turn it on. Just add these two lines of js before rendering the Picker:

emojione.imageType = 'png'; emojione.sprites = true; Hope this helps someone. Awesome little component here, @tommoor, thank you! Here’s a screenshot of my (not yet public) implementation which is going on a dark background:

image

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jonashaefelecommented, Mar 18, 2016

it would be great if the emojione settings could be passed in as props. I ended up forking the repo and setting the following options for emojione:

emojione.imageType = 'svg';
emojione.sprites = true;
emojione.imagePathSVGSprites = '';

then in the component where I render the emoji-picker I loaded the svg inline:

<div style={{display: 'none'}}>
     {require('emojione/assets/sprites/emojione.sprites.svg')}
</div>

using the an inline loader for SVG: dangerouslySetInnerHTML.loader.js

found here: 
module.exports = function(content) {
    return (
        'module.exports = require("react").createElement("span", {' +
            'dangerouslySetInnerHTML: {' +
                '__html: ' + JSON.stringify(content) +
            '}' +
        '});'
    );
};

found here: http://stackoverflow.com/questions/30844298/how-do-i-load-svgs-directly-in-my-react-component-using-webpack

this saves all HTTP requests as the sprite gets bundled with the rest of the app.

I was going to do a PR, but it went off too early. I can still make a PR, if people are interested.

0reactions
jonashaefelecommented, Jun 17, 2016

Make sure you have the SVG inline somewhere.

And be aware this is going to add 4.6MB to your bundle size. So you’ll probably want to split it out into it’s own webpack bundle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preventing Content Reflow From Lazy-Loaded Images
Reflow is a problem because it's a user-blocking operation. It slows down the browser by forcing it to recalculate the layout of any...
Read more >
10 Image Optimization Tips for Your Ecommerce Website
For images that make up borders or simple patterns, make them PNG-8 or GIFs. You can create good-looking images that are only a...
Read more >
How to Improve Your Page Load Speed by 70.39% in 45 ...
CSS sprites work because it's faster to load one big image and use CSS to show the section you want than it is...
Read more >
20 YouTube Tricks, Hacks, and Features You'll Want to Know ...
Here, you'll find a menu of options to the left-hand side with a timeline bar along the bottom of your video. You can...
Read more >
The 17 Most Important SEO Tips for Higher Rankings - Backlinko
You probably already know that you should add keywords to pages that you want to rank. Use your target keyword in your content....
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