V
V
Vasily Kuzin2018-08-07 20:51:21
Fonts
Vasily Kuzin, 2018-08-07 20:51:21

How to reduce font size?

The main part of the website is the constructor, in which the user himself creates the design of the bathrobe. He writes an inscription, then chooses a font for it. There are 6 different fonts to choose from, which are not available in Windows and macOS by default. Google Fonts does not have them either, so they just lie in the fonts folder and are loaded along with the site loading. Because of this, the site loads in about 30 seconds, and the font folder itself weighs several times more than the rest of the site, including images. How can this be fixed? The choice of the font of the inscription in any way should remain, since this is the main function of the site.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Egorov, 2018-08-07
@ExEr7um

Make dynamic data loading. The user selected a font -> loaded it via ajax.
Something like this ->

const url = 'https://fonts.googleapis.com/css?family=Oswald'

const button = document.querySelector('button')
button.addEventListener('click', event => {
    fetch(url)
        .then(response => response.text())
        .then(font => {
    	    const style = document.createElement('style')
    	    style.innerHTML = font

            document.head.appendChild(style)
    })
})

Because the user may not need a constructor at all, he came to read only about the product, and you load him 6 fonts. And if then it will be necessary to support not 6 but 50?
Look at google fonts. They download 20 fonts before opening the page, and it loads in 2 seconds.
Because not the whole font is downloaded, but part of it. You can look on the network. If you start writing in the preview, the entire font will be loaded
First like this ->
Then like this ->
5b69fa014169d151391998.png

V
Vladimir, 2018-08-07
@ruvasik

There is no way to fix it - make a preloader while loading all this.

S
SOTVM, 2018-08-08
@sotvm

in the head, plug in only what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question