Require.js has a never-ending cycle of reloading

Looking to optimize my requirejs project with r.js -o app.build.js

Unfortunately, the result is causing issues on my website.

As shown in the attached video, the page keeps reloading itself and the console indicates that the minified module is constantly being reloaded.

Check out the issue here

Any suggestions?

<script type="text/javascript" src="http://mysite/js/require.js" 
data-main="http://mysite/js/dist/app.out.js" defer async="true">
</script>

View the buggy page:

Configuration in app.build.js

{
    name: "app.main.js",
    mainConfigFile: 'app.main.js',
    out: "dist/app.out.js",
    optimize: "uglify2",
    preserveLicenseComments: false,
    generateSourceMaps: false,
    optimizeAllPluginResources: false,
    findNestedDependencies: false,
    wrap: true,
    wrapShim: true,
    include: ["./require.js"],
}

Code in app.main.js

requirejs.config({
    paths: {
        require: './require',
        jquery: './vendor/js/jquery-2.1.1.min',
        underscore: './vendor/js/underscore-min',
        backbone: './vendor/js/backbone-min',
        hbs: './vendor/js/hbs/hbs',
        handlebars: './vendor/js/handlebars-v4.0.5',
    },
    hbs: { // optional
        helpers: true,            
        templateExtension: 'hbs', 
        partialsUrl: ''           
    },

    shim: {
        handlebars: {
            exports: 'Handlebars'
        },
        backbone: {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        },
        underscore: {
            exports: '_'
        }
    },

});

requirejs(["app_config", "app"],function(cfg, App, noop_ahoy){
    return App.initialize();
});

Update

I have multiple files, some of which contain anonymous functions. Could this be the issue?

Further details here

define([
    ...
    "jquery"
],function(

Answer №1

An issue arises from a common mistake that can easily be made. When utilizing RequireJS, it is crucial to load the bundle with the provided code as shown below:

<script type="text/javascript" src="http://mysite/js/require.js" 
         data-main="http://mysite/js/dist/app.out.js" defer async="true">
         </script>

The key point is to have src="path/to/require.js and data-main="path/to/bundle.js", which is essential.

The error occurred when RequireJS was included in the bundle and the script tag was modified to something like:

<script type="text/javascript" src="http://mysite/js/bundle.js" 
         data-main="http://mysite/js/bundle.js" defer async="true">
         </script>

Due to some anomaly, this leads to recursive loading of the same script repeatedly because somewhere within bundle.js you require require, causing it to fetch bundle.js again, resulting in chaos. This appears to be the likely explanation. Since your current page does not appear to utilize the bundled script anymore, I am unable to confirm this.

To resolve this issue, ensure that RequireJS itself is not included in the bundle, as specified in the documentation.

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

How can you calculate the partial years between two dates using momentjs?

Can someone guide me on how to calculate the number of years that have passed between two dates using momentjs, taking into account partial years? For instance, if I select Dec 30, 2017 to Jan 02, 2020, I am looking for the output to be 4, or even better, ...

Creating a progress bar feature using local storage in JavaScript

Is there a way to retain the progress of the countdown timer with a progress bar on page reload? Here is an example of what I am trying to achieve: https://codepen.io/Rudchyk/pen/qNOEGj <div id="progressBar"> <div class=& ...

In jQuery, a dropdown selection can be filled with multiple textboxes sharing the same class

I'm experimenting with the idea of using multiple textboxes with the same class filled with different dropdown options that also have the same class. However, I am encountering some issues. When I click on a dropdown option, it changes the value in a ...

Updating Variables in Azure DevOps Code Prior to DeploymentORModifying Variables

Can Azure DevOps automate code updates upon release? For instance, in my React app, I have a setting file with export const ISPROD = false. I want Azure DevOps to modify this value to true before building and deploying the app. Is this achievable? Please ...

Eternal Node Bug

I'm attempting to utilize node-forever but encounter an error upon starting it. The filename I used is start.js var forever = require('forever-monitor'); var child = new (forever.Monitor)('app-index.js', { 'silent&apo ...

Updating the values of parent components in Vue.js 3 has been discovered to not function properly with composite API

Here is a Vue component I have created using PrimeVue: <template lang="pug"> Dialog(:visible="dShow" :modal="true" :draggable="false" header="My Dialog" :style="{ width: '50vw' }" ...

Retrieve the date values in ISO 8601 format from Sqlite database

Currently, I am using Knex.js to retrieve records from a SQLite database. My goal is to then convert these records into JSON as part of a web api. As it stands, the dates retrieved from SQLite are in the format 2018-01-01 00:00:00.000 Instead, I would lik ...

YouTube's embedded video player is invincible and cannot be destroyed

Having trouble destroying an embedded YouTube video on the Plyr player. The player.destroy() method is being called without any errors, but it doesn't actually destroy the player. This issue is causing the previous video to load instead of a new one ...

Only fire the click event of the parent div if none of the child elements are clicked

Here is a fiddle I've prepared for reference: https://jsfiddle.net/9m4bgyq8/16/ The issue I am facing is that I am attempting to wrap a checkbox and label within a div, and apply a click event to the div. The intention is for the click event to only ...

Arrange objects in an array according to the order specified in another array

Here is my array of car makes: const makes = [ {id: "4", name: "Audi"}, {id: "5", name: "Bmw"}, {id: "6", name: "Porsche"}, {id: "31", name: "Seat"}, {id: "32", name: "Skoda"}, {id: "36", name: "Toyota"}, {id: "38", name: "Volkswagen"} ] Now, I want to o ...

Enhancing code readability in vim with custom Javascript syntax highlighting

Is anyone else experiencing issues with VIM's syntax highlighting for Javascript? I have noticed that at times, the highlighting seems to disappear and I have to scroll around to get it adjusted properly. Does anyone know of any workarounds or soluti ...

Loading Images in Advance with jQuery, Native JavaScript, and CSS

After successfully implementing a method to hover on a small image and load an additional image to the right side of the page, I am now looking to enhance user experience by preloading images. Is there a way to preload an image using JQuery, allowing it t ...

Using middleware is not supported when using "output: export"

After countless attempts over several days and more than a thousand combinations, I am still facing the same issue with my files. Middleware.js: import { NextResponse } from "next/server"; export const protectedRoutes = ["/profile", ...

Creating a Bootstrap 4 navigation bar that sticks to the bottom of the page, allowing the main content to smoothly scroll

Despite my best efforts, I can't seem to get this to work as intended. I'm struggling to prevent the "main" content (in this case, the images) from disappearing under the bottom navigation bar. In the provided jsfiddle link, you can see that th ...

A solution for Array.includes to handle NaN values

While browsing some Javascript blogs, I stumbled upon the Array prototype methods .indexOf and .includes. I noticed that if an array includes NaN as a value, indexOf may not be able to detect it, leaving us with the option of using .includes. However, cons ...

configure Next.js to exclude a specific subPath within the host from being processed

I've encountered an issue with my public_html directory where there is a folder named blog that is unrelated to my NextJs app. After deploying the app on the host, everything works fine until I try to access the blog section using the following URL: w ...

Unusual sequence of JQuery Ajax calls

Within my website, there is a project div that is displayed using EJS. The data for the projects in EJS are rendered using a forEach loop, resulting in multiple similar divs appearing on the page. Each project div is assigned an id for identification pur ...

The Sequelize findOne method fails to return the desired results, resulting in an empty

My findOne function with include is not working as expected. It is not returning any data. I am missing data for Deal, which is related to Redemption [] <- I should have data here. Deal.belongsTo(models.Redemption, { foreignKey: 'redemptionI ...

Using Bootstrap to present information with a table

Presenting information in a Bootstrap table with Vue.js I have gathered the necessary data and now I want to showcase it in a table using bootstrap. Currently, I have achieved this using SCSS as shown in the image below: https://i.sstatic.net/XN3Y4.png ...

Shattered raw emotion

Does anyone have any insight on how to resolve this error? I've hit a roadblock trying to figure out the issue in the message below. Here is the snippet of code: :label="` ${$t('cadastros.clientes.edit.status')}: ${cliente.status === ...