Using Nuxt.js to preload .woff fonts and load them with @font-face

Looking to boost my Google score and Google is recommending using preload for the two custom fonts I'm using, which could save a significant 4.5 seconds? Currently, the fonts are stored in assets/fonts and loaded via @font-face in typography.scss file, which is then included in nuxt.config.js under css: [ '@/assets/scss/typography.scss', ]

Answer №1

Are you looking for a way to preload fonts in your Nuxt.js project? One solution is to call a render function in the nuxt.config.js file that will preload fonts, scripts, and styles, making them available on the client side without needing to load the font in your scss file. Give this code snippet a try:

//nuxt.config.js

module.exports = {
  mode: ' your mode ',

  ...

  render: {
    bundleRenderer: {
      shouldPreload: (file, type) => {
        return ['script', 'style', 'font'].includes(type)
      }
    }

  },
  ...

}

It's also recommended to store your fonts in the static folder like so: /static/fonts/yourfonts.woff2

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

transmitting information using dataURL

Hey there! So I've got this code that does a neat little trick - it sends a dataURL to PHP and saves it on the server. In my JS: function addFormText(){ $('body').append('<input type="hidden" name="img_val" id="img_val" value="" /& ...

Vue: unable to switch to a different page

I am a newcomer to Vue and I have successfully created a dynamic page that fetches questions, user names, and categories from an API. Everything is displaying correctly, but I am facing an issue with making certain elements clickable. Specifically, I want ...

AngularJS application is throwing an error indicating provider $q is not recognized

Could someone please advise on what might be the issue with my code snippet below: var app = angular.module('app', [ 'angular-cache', 'angular-loading-bar', 'ngAnimate', 'ngCookies', &a ...

Navigating to a Laravel web route directly from a Vue component without relying on Vue Router

This question may seem repetitive, but I have searched everywhere for a solution. I am using laravel-vujs mix and have integrated web routes and api routes in the same project. Currently, I am working on creating a register API function called registerna ...

Need help transferring variables from JavaScript to Ajax using jQuery Tabledit?

I am currently utilizing the jQuery plugin Tabledit, which can be found here. When I implement an inline edit similar to example 3, it triggers my PHP page. However, I am unsure of how to transfer the edited information to the new PHP page in order to upda ...

Searching through the use of autocomplete with alternative parameters

In the example below, - https://codesandbox.io/s/g5ucdj?file=/demo.tsx I am aiming to achieve a functionality where, with an array like this - const top100Films = [ { title: 'The Shawshank Redemption', year: 1994 }, { title: 'The Godfa ...

Next.js Error: The text displayed on the page differs from the HTML rendered by the server

Currently, I am facing an issue with the error "Error: Text content does not match server-rendered HTML." Here is my scenario - I have received a dateTime from an API, for example '2022-12-25T11:22:37.000Z', and I want to display it on a compone ...

Guide on transferring a JavaScript value from Laravel Blade to a controller

Click the button below to initiate the process: <a onclick="myFunction()" href="{{ route('test')}}" data-toggle="tooltip" title="Release Funds" class="datatables__button"><i class=" ...

Utilizing JavaScript to retrieve data from incoming Servlet requests

Currently, I am working on a web app using Java EE, following a specific pattern. The process involves sending a query to the database from a DAO pattern. Once the result of the query is obtained, it is passed to the controller (servlet), which in turn pas ...

Design a personalized context menu for right-click actions (copy, paste, cut) to be used across all web pages within any browser, rather than limiting it to individual pages

Looking to create a customized UI context menu with copy-paste options and came across a jQuery plugin that can do this for a specific HTML element. My question is, how can I implement this across all web pages in my application, rather than just one indi ...

Exploring the 3D Carousel Effect with jQuery

After creating a 3D carousel using jQuery and CSS3, I am looking to enhance it with swiping support. While there are plenty of libraries available for detecting swipes, I specifically want the carousel to start rotating slowly when the user swipes slowly. ...

"Utilizing the jQuery append method to dynamically insert an SVG element

Currently, I'm in the process of constructing a graph by utilizing svg elements and then dynamically creating rect elements for each bar in the graph through a loop. I have a query regarding how I can effectively pass the value of the "moveBar" varia ...

What could be causing my component to not refresh when used as a child?

I have been experimenting with some code to track rerenders. The initial approach failed when passing <MyComponent> as a child component. it("should return the same object after parent component rerenders", async () => { jest.useF ...

Leveraging the power of jQuery click function to retrieve values from a dynamically generated select element using PHP

In my PHP code, I have a function that dynamically generates select boxes for each field of a table. Specifically, the field name is payment_status. The PHP script retrieves the value associated with this field from the database and sets it as the initial ...

Is there a way to navigate back and forward in browsers for single page applications?

Working on a Single Page Application(SPA) has led me to utilize htmlPushState and window.onpop in order to maintain browser back and forward functionality while changing CSS styles and calling backend APIs. Currently, my SPA project consists of 5 pages, b ...

How can I make transparent png sprites in three.js cast and receive shadows?

Is there a way to enable sprites in three.js to cast and receive shadows without rendering the alpha channel as a shadow? I have all my assets saved as transparent PNGs, and while mapping textures onto sprites is working well, I'm struggling with the ...

JQuery may be successfully loaded, but it is not functioning as intended

Just started dabbling in JQuery (I'm a newbie) but I'm having trouble getting it to work! Initially, it worked a couple of times but then suddenly stopped working (pretty strange). I made some changes and now it doesn't work at all. JQuery a ...

When there are additional parameters following .../foo.png/, the Img-src does not properly resolve the URL

Here is the link to my URL that I am trying to use: Whenever I try to open this link in my browser, it displays a raw image. However, when I reference it in an <img src> tag, I do not get the desired image returned. Strangely, if I remove everything ...

Retrieve data from each object in the API and then initiate a new request

Here is how my first post request appears: this.http.post('http://localhost:8080/api/userfilm/get/', { name: this.name }) This request returns an array of objects with the property 'filmid'. Now, let's take a look at my sec ...

Finding the value within a specified range of two numbers in Vue.js

When my code generates a result of 0, I need to determine the corresponding value based on the basic_salary. For example, if the basic_salary is 40,000, it should return the value of "ee": 400. <table class="table table-hover table-borde ...