Tips for optimizing three.js for mobile devices

This past week, I dedicated my time to creating a personal website for myself.

It features information displayed in semi-transparent divs layered over an animation of a spinning cube (pretty basic concept, right?).

However, the issue I encountered is that while examples on threjs.org/examples run smoothly on mobile devices, my site seems to struggle to render Three.js components on mobile platforms.

I have tried several solutions so far:

Firstly, I made sure that my website gracefully degrades from WebGL by incorporating detector in index.html and using the following code snippet to declare my Three.js renderer:

renderer =  Detector.webgl ? new THREE.WebGLRenderer({ alpha: true }): new THREE.CanvasRenderer({ alpha: true });

Secondly, I organized my code well with init, animate, and render methods.

Thirdly, I added stats.js (as seen in the examples) and adjusted my HTML, CSS, and JS files accordingly.

Despite these efforts, I am still unable to resolve the issue!

The current state of the page displays perfectly on desktops and responds effectively to window resizing, but when accessed via a phone, nothing appears in the background.

From what I can tell, I'm following the same approach as the examples, yet I'm not achieving the desired performance on mobile devices.

Your assistance would be greatly appreciated!

You can view the site here: krewn.github.io, which consists of only three files each fewer than 80 lines.

Edit: After making some changes (fixing undeclared variables and adding "use strict"), the 3D rendering now works on both desktop and mobile, except for mobile Mozilla browsers - which is peculiar since the examples on threejs.org work flawlessly on mobile Mozilla...

Answer №1

As pointed out by @2pha in a prior comment, your website seems to be experiencing some technical issues:

An error occurred: Block-scoped declarations (let, const, function, class) are not currently supported outside of strict mode.

You can try including the following code snippet:

"use strict";

at the beginning of all your JavaScript files. By doing so, I believe your site will operate smoothly on both desktop and mobile devices.

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

Exploring the incorporation of various local fonts in NextJs version 13

Having trouble adding multiple local fonts to nextjs 13. According to the instructions in the documentation, you should follow these steps for a single file. I attempted to import two files like this: import '@/styles/globals.css'; import localF ...

Issue with Jquery checkbox calculator constantly displaying Not a Number (NaN)

I'm facing an issue with jQuery. The Custom Wpform Checkbox Field is returning NaN. HTML <div class="wpforms-payment-total"> $ 85 </div> <input type="checkbox" name="myBox2" size="1 ...

Limiting the current date in javascript according to specific hours and minutes

Prevent users from selecting the current date if the current time exceeds a specified hour using JavaScript. This is what I have attempted: var d = new Date(); var restricttime = '<?php echo $restrictTime->time_restriction ?>'; var res ...

Utilizing Nextjs version 13 for implementing an API route with the ytdl-core

Recently, I've been experimenting with setting up a basic YouTube downloader using ytdl-core & nextjs. In my code, there's an onClick function that makes an API call. const onClick = async () => { await fetch("/api") .then(async (re ...

Is there a way I can showcase the top 100 iOS apps from the App Store on my website in a manner similar to

Is there a way for me to showcase real-time iOS AppStore rankings on my Wordpress blog? I am looking to feature the following categories: Top 75 Paid Apps Top 75 Free Apps Popular App Sales I am inspired by sites like 148Apps or AppAdvice. Any insight ...

The date selector is failing to accurately reflect changes in the date objects

I've integrated a date-time picker from this source https://github.com/DanielYKPan/date-time-picker to manage 'beginning' and 'end' date objects (refer to selectedMoments in the TypeScript code) for a date selector. However, when I ...

Using jQuery to insert a div class with PHP referenced

My variable stores a color name. Here is an example: <?php $myvar = blueColour; ?> I want to apply this value to the body of an html page using jQuery: <script type="text/javascript"> jQuery(body).addClass("<?php echo $myvar; ?>"); < ...

Error Encountered: Unable to Locate Node Modules on Ubuntu Version 20.04.5

I am a Windows 10 user who utilizes WSL. Initially, I was working with Ubuntu 20.04.5 from the Microsoft Store and running node commands smoothly. However, my attempt to upgrade to Ubuntu Jammy (22.x) resulted in errors when trying to use nodejs after inst ...

Is it advisable to solely rely on CDN for incorporating Bootstrap JS components, or are there any potential drawbacks to

I'm in the process of customizing Bootstrap using my own styles, by utilizing a local version of the source SASS files as outlined in the official documentation, and importing them into a custom.scss file. My main focus is on altering the visual aspe ...

using an x-api-key in the header of a service within Angular

I have been struggling with calling an x-api-key in the header of my Angular service, and I'm encountering an authorization error. It seems like there may be a syntax issue in my code. import { Injectable } from '@angular/core'; import { Htt ...

Tips for organizing components in jQuery Mobile

Displaying a survey creation form: <!-- HTML structure --> <div data-role="page" data-theme="b"> <div data-role="header"> <h1> Create Survey </h1> </div> <div id="main" data ...

Flask and Ajax make it easy to work with multiple datatables that are connected to

Currently, I am working with 2 datatables in my project. The first one is populated using the following code snippet: {% block scripts %} <script> $(document).ready(function () { $('#data').DataTable({ ajax: '/api/dat ...

Enhance your textbox with more detailed descriptions than just displaying NaN

I am working on a form that includes select boxes. If a user selects an option from "Convert From" and another option from "Convert To" but does not enter a number in the input field, instead of displaying NaN in the result text box, I would like to show ...

The local ESlint plugin is causing issues with installing dependencies on our CI environment

I have developed a personalized ESLint plugin specifically for one project and have not made it public. It is saved in a folder within my project because I only intend to use it internally, and I see no need to create a separate repository for it. However, ...

Incorporate the results from ajax into a function callback within a plugin (jQuery)

How can I access the output of an AJAX call within a callback function in my plugin? My plugin is designed for a contact form that sends data via AJAX, and I need to be able to view the output in a log or alert. The plugin already includes a callback funct ...

Ensuring a component stays active while navigating in Angular 2

Currently, I have a javascript application that heavily relies on jquery. It's not the most visually appealing, difficult to maintain, and definitely in need of a framework upgrade. That's why I'm in the process of migrating it to be compati ...

The main.js file will be served by nodeJS using express

After developing a nodeJS server using express, I encountered an issue where the server was only delivering the index.html file and not the accompanying main.js file. Both files are located in the same directory. app.get('/', function (req, res) ...

Why doesn't a JavaScript variable update across files as expected?

I am facing an issue with two files in my project: index.js let list = []; function add() { //list.push("item"); list = ["item"]; console.log("B. list length " + list.length); } module.exports = { add, ...

Sending data from child components to parent components in Angular

I'm facing an issue with retrieving data from a child array named store within user data returned by an API. When trying to access this child array in my view, it keeps returning undefined. Code export class TokoPage implements OnInit { store= nu ...

What are the techniques for integrating PHP code into JavaScript/Ajax?

I am curious about how to integrate PHP code into JavaScript/Ajax. Here is the PHP code I am working with: if ($folder = opendir('data/Tasklist/')) { while (false !== ($file = readdir($folder))) { if ($file != '.' && $ ...