Prevent the need for image conversion by pre-transforming them into .webp format before using them

I have a small Nextjs app running on the lowest tier of DigitalOcean. I am experiencing slow image rendering times, with images taking nearly 500ms to load even though they are only 1-2 KB in size. Could this delay be due to the conversion process from the original .png file to .webp? If so, how can I adjust next/image to handle both pre-converted .webp and .png files, and select the appropriate format based on browser support for .webp?

Answer №1

Here is an example you can experiment with

//somewhere else in the script    const path = imagePath, const title = imageTitle
  <picture>
      <source
        type="image/webp"
        srcSet={`/images/${title}.webp`}
      />

      <source type={`image/${format}`} srcSet={path} />
      <img
        src={path}
        alt={props.alt ?? ""}
        width={props.width}
        height={props.height}
        className={props.className}
      />
    </picture>

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

The functions have been triggered, yet their outcomes do not align with expectations. What could be the root of the

Following on from the previous query. In Firebase console, it has been verified that functions are being executed. However, the browser does not display any results. I am looking to modify the meta tag and update the URL. Is there an issue with my code? ...

The HTML table is not fully filled with data from the XML file

Trying to populate an HTML table using XML data retrieved from an AJAX call is proving to be a challenge for me. The main issue I am facing is the inability to fully populate the HTML table. Being new to AJAX, understanding how XML interpretation works an ...

The removal of anonymous function callbacks in jQuery.Callbacks is being discussed

Once a callback function is added to $.Callbacks(), it can be removed as shown below: var callbacks = $.Callbacks(), foo = function() { console.log('Hello world') }; callbacks.add(foo); callbacks.fire(); // logs 'Hello world' call ...

Learn how to send messages to specific clients by using the property names of a JavaScript object

In my code, I have an object called var usernames = {}; When the client logs in, they emit addUser to the server. socket.on('addUser', function(data) { if (usernames[data] == undefined) { socket.username = data; username = ...

What steps should I take to address the most recent error I encountered while using material-tailwind with next.js version 13

Encountering a simple error while setting up a new Next.js 13.5 project and installing material-tailwind. During testing, everything runs smoothly in development mode when clicking on a button imported from material-tailwind. However, issues arise when try ...

Selenium is encountering a validation error when selecting a value from a Drop Down menu

My current project involves automating website testing through selenium. I have encountered a scenario where I need to fill in a mandatory drop-down field. The code snippet I am using to select the drop-down value is as follows: select = Select(find_eleme ...

Is it possible to update the src attribute of an iframe using a separate HTML file?

My radio elements are set up to update an iFrame with JavaScript code, which is working perfectly fine. Below that, I have a button that creates another iFrame in an HTML Division containing a list of buttons. My goal is to click one of these buttons in t ...

Disable sorting options in the Datatable ColumnFilterWidget

I'm currently working with datatables ColumnFilterWidget and I'd like to prevent the widget from sorting the values displayed in the select box. Despite trying the "bSort": false option of the ColumnFilterWidget, it doesn't seem to have any ...

Unable to register an onclick event for every individual checkbox

I am looking to implement an onclick function for each checkbox added in a row of a datatable. Check out the image below: [Insert Image Here] The issue I'm facing is with the following code snippet: var tablei = $('#domains_list').Da ...

Dealing with Typescript: Reducing an object containing other objects

Having some difficulties implementing a reduce function with TypeScript - struggling with types and return value. Facing issues with omitting controls from Storybook, causing two TypeScript errors indicated in the code marked ** ERROR ** Seeking advice on ...

Combining Extjs combo with autocomplete functionality for a search box, enhancing synchronization capabilities

When using autocomplete search, I've encountered an issue. If I type something and then make a mistake by deleting the last character, two requests are sent out. Sometimes, the results of the second request come back first, populating the store with t ...

What is the process of defining a route for a JSON response in an Express application?

I've been following an Angular tutorial on handling form submissions with promises, which I found here. My server is running on Node and I'm using Express to manage routes. However, when I submit the form and reach the line var $promise = $http. ...

Getting the selected value from a RadioButtonList in an aspx file

I am working on an aspx application that includes a RadioButton list structured like this: <asp:RadioButtonList runat="server" ID="rblIsDiesel" RepeatLayout="Flow" RepeatDirection="Horizontal"> <asp:ListItem Text="Diesel" class="carFuel" Valu ...

I desire to share the JSON information and receive the corresponding response data

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> ...

Show a random number within a Bootstrap tooltip

I am trying to make a bootstrap popover display a random number every time it is clicked, but my current implementation is only showing the initial number generated and does not update on subsequent clicks. Below is my code snippet: <button type=&qu ...

Utilizing Vue's v-for directive to manipulate data through custom looping

When I loop through my data using v-for, I find myself unsure of how to display the data with a custom looping method, such as using modulus. I aim to display the data in groups of three items, assigning a different class to every 3 items. The desired st ...

The 'initializeOnMount' property is a necessary requirement within the definition of the 'MoralisProviderInitializedProps' type

I encountered an unexpected issue with the code below: Type '{ children: Element; appId: string | undefined; serverUrl: string | undefined; }' is not compatible with type 'IntrinsicAttributes & MoralisProviderProps'. The property ...

Quickly redesigning the appearance of file input using javascript and jquery. Seeking assistance to correct css issues on jsfiddle

Hey there, I've been working on styling the input[type="file"] element and could use some assistance. Like the saying goes, "One JSfiddle is worth 1000 words," so here's the link to my example: --- For more details, click here: http://jsfiddle.n ...

Troubleshooting: Bootstrap's shown.bs.tab event failing to function

I'm currently using the Flexy template (built with bootstrap) and I am struggling to make the shown.bs.tab event on tab function properly. Interestingly, I was able to get it working on JSFiddle. Below is the code snippet from my template that seems ...

Flatbuffers does not exist in this context

Currently, I am working on a nodeJs application that involves the use of Google Flat Buffer. After installing flatc on my MacBook Pro, I compiled the schema below: namespace MyAlcoholist; table Drink { drink_type_name: string; drink_company_name: stri ...