Troubleshooting browser cache issues when using webpack chunks and vue.js components

The Issue

I am facing a frustrating challenge with cached Vue.js components. Strangely, I cannot replicate this issue on my own devices, but whenever we push client-side updates, users start complaining about broken interfaces. The only solution seems to be clearing the browser cache every time.

My setup involves Laravel + Vue.js in a multipage application format.

Approach

All components are consolidated into one file that is included in app.js as shown below:

Vue.component('task-feed', () => import('./components/task/task-feed'/* webpackChunkName: "/js/components/task-feed" */));
Vue.component('task-item', () => import('./components/task/task-item'/* webpackChunkName: "/js/components/task-item" */));

These are async Vue.js components.

Furthermore, I have configured webpack.mix like so:

let mix = require('laravel-mix');
const webpack = require('webpack');
const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
const WebpackChunkHash = require('webpack-chunk-hash');
mix.disableNotifications();
let config = {
    watchOptions: {
        ignored: /node_modules/
    },
    resolve: {
        alias: {
            'vue$': mix.inProduction() ? 'vue/dist/vue.runtime.min.js' : 'vue/dist/vue.runtime.js',
        }
    },
    output: {
        chunkFilename: mix.inProduction() ? '[name].[chunkhash].js' : '[name].js',
    },
    plugins: [
        new webpack.HashedModuleIdsPlugin(),
        new WebpackChunkHash(),
        new ChunkManifestPlugin({
            filename: '/js/chunk-manifest.json',
            manifestVariable: 'webpackManifest',
            inlineManifest: true,
        }),
    ],
};

mix.webpackConfig(config);

Incorporating the ChunkManifestPlugin, I generate chunk-manifest.json and load it in the main layout through this code snippet:

window.webpackManifest = JSON.parse(@json(file_get_contents(public_path('/js/chunk-manifest.json'))));

Queries

Any thoughts on what might be causing this issue? Open to suggestions for resolving it effectively?

Answer №1

In your `webpack.mix.js` file, make the following changes:

mix.config.webpackConfig.output = {
    chunkFilename: 'scripts/[name].[chunkhash].js',
    publicPath: '/',
};

For further details, check out this informative article.

Answer №2

Update webpack.mix.js to include file versioning

let currentVersion = 1;

mix.config.webpackConfig.output = {
    chunkFilename: 'v/' + currentVersion + '/scripts/[name].js',
    publicPath: '/',
};

mix.js('resources/js/app.js', 'public/v/'+currentVersion+'/js')
    .sass('resources/sass/app.scss', 'public/v/'+currentVersion+'/css');

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

Adjusting the letter spacing of individual characters using HTML and CSS

Is there a way to set letter-spacing for each character with different sizes as the user types in a text box? I attempted to use letter-spacing in CSS, but it changed all characters to the same size. Is there a possible solution for this? Here is the code ...

Creating a Choropleth map using React: A step-by-step guide

Currently, I am attempting to develop a Choropleth map of Spain in React using Leaflet. Below is the code I have written: import React, { useEffect, useRef, useState } from 'react'; import { MapContainer, TileLayer, GeoJSON, FeatureGroup } from & ...

Error: The query has already been processed:

I'm encountering an issue while attempting to update the document. The error message indicates that the query has already been executed. MongooseError: Query was already executed: footballs.updateOne({ date: 'January 4' }, {}) app.post(& ...

Knockout.js dropdown pre-selection in nested JavaScript objects is functioning smoothly in KO 2x versions, but there seems to be a compatibility issue with KO 3x versions

This is a sample data that will be loaded from the server in JSON format and constructed into the below object graph. It consists of an array of "Choice" objects, each with properties like id, name, stages, & currentStageId. The "stages" property in th ...

Choose from a dropdown menu to either activate or deactivate a user account

I'm new to php and I need help getting this code to function properly delete.php <?php include_once 'dbconfig.php'; if($_POST['del_id']) { $id = $_POST['del_id']; $stmt=$db_con->prepare("UPDATE tbluse ...

Is there a live password verification tool available?

Currently, I am conducting some initial research for my school's IT department as a student employee. The students at our institution are required to change their passwords every six months, but many of them struggle with the various password regulati ...

Troubleshooting sequential image loading in KineticJS and resolving issues with opacity tween when setting fillPatternImg

In my latest project using KineticJS, I am developing a small app that generates multiple nodes in the form of RegularPolygons. Once the stage has loaded (activated with play();), I proceed to sequentially fill each node with an image pattern using loadIma ...

When modifying v-model directly in a Vue instance, the Vuetify component on the screen may not update its displayed value

Within my Vue component example (utilizing Vue 2 and Vuetify 1), I have implemented an input field for user data entry. However, I am looking to programmatically alter the input field's data to a specific value. For instance, in this scenario, I aim ...

Splitting a string in Angular.JS using ng-repeat

Just diving into the world of Angular.JS and grappling with the concept of implementing ng-repeat. Within my scope, I have a data object derived from JSON fetched from my database. Among the returned 'fields', one particular field can either be ...

Find all relevant employee information at once without the need for iteration

I have structured two JSON arrays for employee personal and company details. By inputting a value in the field, I compare both tables and present the corresponding employees' personal and company information in a unified table. <html> ...

Activating events with Jquery

Can anyone help me with this HTML and jQuery issue I'm facing? When I click on an image for the first time (when it has the class 'hide'), the first jQuery click function is executed. However, when I click on the image again, the second func ...

Deciding between Bull queue and Database Triggers

My current project requires creating records in the database for users on a recurring basis, such as every Monday weekly or biweekly. I have identified two potential solutions to achieve this goal. One option is to utilize Database Triggers to generate ...

Vuetify SassError: Blank line expected

Encountered an issue while trying to integrate Vuetify with webpack. The error message "SassError: Expected Newline" keeps popping up during the process: 18:25:32 webpacker.1 | Module build failed (from ./node_modules/sass-loader/dist/cjs.js): 18:25:32 w ...

Sending the array data to the component and executing it

Trying to familiarize myself with Vue2, but I am having issues with the "markers" array not updating on the map. How can I make this array reactive and ensure that the map markers change accordingly? Thanks for any assistance! views/Map.vue <template ...

Adjust the scope variable upon submission and refresh the display in AngularJS

Currently, I am working on my first web app using angularjs and facing an issue where the page does not update with new values once the user submits text or numbers in an input box. For this project, I am utilizing Java8, MongoDB, angularJS, and twitter b ...

Converting JSON data into objects in JavaScript

My task involves processing a large JSON list with over 2500 entries, formatted as follows: [ ['fb.com', 'http://facebook.com/'], ['ggle.com', 'http://google.com/'] ] This JSON list represents pairs of [&ap ...

Achieving the functionality of keeping the search query box and alphabetical search options visible on the page even after performing a search and displaying the results can be done by

I have set up a PHP page with search query field and alphabetical search options. When submitting the query, the results are displayed on the same page; however, I would like the results to show in the same location as the alphabetical search. Currently, ...

Tips for building a dynamic view using Angular

I am working on a project where I need to dynamically generate multiple horizontal lines using data from a JSON file, similar to the example in the image below. https://i.sstatic.net/MthcU.png Here is my attempt: https://i.sstatic.net/EEy4k.png Component. ...

Executing webpack from a shell script can be a powerful tool for automating the build process

Recently, I created a toy application with the assistance of the yeoman react webpack generator. Now, I am looking for a way to simplify the deployment process by using a shell script. The package.json file contains the following script snippets... "scri ...

Unable to add the div using a jQuery click event

Hey there, I'm looking to add a div dynamically when clicking on another div. Check out the code snippet below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title></title> <script src= ...