Using a separate JavaScript file for bundling and components in a Vue.js application helps to optimize

I currently have over 100 components that are utilized in various Laravel blade files.

My system is service-based, allowing different types of users to access different routes. For example, there are administrator panels for us, admin panels for institutions, employee panels, student panels, guardian panels, and more.

As an administrator, we have access to all panels. We manage over 20 institutions within the same system, with that number increasing every day.

When an admin accesses the system, there is no need to load the entire js file (which is over 6MB+ when running 'npm run prod'). However, since we have only one js file in the entire project, the admin user must load the entire 6MB+ js file. In 'npm run watch' mode, the js file size increases to over 13 MB!

How can I set up different js files for different users or use multiple js files?

What measures can be taken to optimize my app for end-users' faster access?

Here's an example of a blade file structure:

<institution-student-attach-form
            get-site-base-country-list="{{route('get-institution-base-student-list')}}"
            student-details-view="{{route('student-view',[''])}}">

</institution-student-attach-form>

I utilize props to obtain the routes in the component files.

Edit

     mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css').extract();

https://i.sstatic.net/rT7Ql.jpg

https://i.sstatic.net/BC9tw.jpg

/**
  • We will first load all JavaScript dependencies for this project, including Vue and other libraries. This serves as a solid foundation for building robust web applications using Vue and Laravel.

//require('./bootstrap');

import Vue from "vue";
window.Vue = Vue;
...
Vue.filter("round", function(value) {
    return parseFloat(value).toFixed(0);
});

const app = new Vue({
    el: "#app",
    i18n,
    components: {},

    methods: {},
    mounted() {
        console.log("d" + document.documentElement.lang.substr(0, 2));
    }
});

Answer №1

To optimize the Vue framework core library usage, you can utilize mix to extract it and then compile the necessary components for each specific page into separate bundles with webpack.

Here's an example:

mix.js(src, output).extract();

You should also create JS files that contain the registration of Vue components, like institution.js.

Vue.component('institution-student-attach-form', require('./components/institution-student-attach-form.vue').default);

Compile them into a separate file like this:

mix.js('resources/js/app.js', 'public/js')
   .js('resources/js/institution.js', 'public/js')
   .extract()
   .sass('resources/sass/app.scss', 'public/css')

Finally, include this compiled file in the specific blade view, repeating these steps for other scripts and views as needed.

I hope this explanation is helpful!

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

Hover over the text only, not the entire row

Is there a way to create a mouse hover effect on text only, without affecting the entire row? I attempted using Position(), but didn't have success. Here is a link to the fiddle I created: <ul id='ulid'> <li>Task1</li> < ...

Is there a more efficient method for managing Express rendering based on whether the request is an AJAX post or an HTML form submission?

Currently, I am working on an HTML form and incorporating jQuery's AJAX post feature to retrieve information based on the success or failure of a database insertion. Within my code, I have set the ajax post variable to true when utilizing AJAX postin ...

The functionality of a radio button triggering a form submission to different pages is experiencing issues with Firefox

This piece of code is designed to submit a form when a radio button is clicked, and depending on which radio button is selected, the form action should change. While this code works fine in Chrome and Opera, it doesn't seem to function properly in Fir ...

Implementing Mocks for window.eventBus.$on in Vue.js using Jest Framework

Looking to verify the emitted value for test case coverage. window.eventBus.$on('filter-search-content', () => { console.log('The event was emitted successfully'); this.showFilter = true; }); I attempted the following approach, ...

The property 'class' is required for ".builders['browser']"

Upon successfully installing the dependencies using npm install, I encountered an error while attempting to run the server: Schema validation failed with the following errors: Data path ".builders['browser']" should have required property ' ...

Transforming Django models into JSON format to be utilized as a JavaScript object

Looking to retrieve model data as an object in Javascript, I've been using the following approach in my Django view: var data = {{ data|safe }}; Here is how my view is set up: context = { 'data': { 'model1': serializ ...

JavaScript code to locate the most pertinent strings within an array based on a specific substring

I'm working with a large array containing names of people, such as: let names = [ "John Brown", "Tristan Black", "Carl Jobbs", "Aidan Burrows", "Taylor Joe" ]; When given an input, I want to return the top 5 most relevant results ...

Navigating through nested promises can be a daunting task within the world of JavaScript and Angular

Function 2 relies on the return of Function 1, while Function 3 uses both returns. How can I clean up this process? Currently, Function 3 is only giving me undefined values. Below are my 3 functions: Function1 $scope.nombreCompetencesATraiter = function ...

Feeling lost when it comes to understanding how vue3 handles reactivity

Within vue3's reactive framework, there exists a stack known as the effectStack. I'm puzzled by the necessity of it being a stack if the effect is immediately removed with pop() after push(). Is there a scenario where the length of effectStack co ...

The sticky navigation and scroll to top features both function perfectly on their own, but when used simultaneously, they do not work

I'm facing an issue with two scripts on my website - when they are separate, they work perfectly fine but together, they don't seem to function properly. What could I be missing here? Script 1: window.onscroll = function() {myFunction()}; var n ...

Utilizing jQuery with the themoviedb JSON API

Attempting a seemingly simple task here - extracting input from a text field and using it to search the themoviedb.org database via the API. With jQuery and themoviedb.org APIv3 in use (JSONP supported), all I'm getting in return is the following res ...

Adding a class to a div upon loading: A guide

Currently using the following script: $(document).ready(function() { $(".accept").change(function () { if ($(this).val() == "0") { $(".generateBtn").addClass("disable"); } else { $(".generateBtn").remove("dis ...

How can I dynamically preload state in React / Redux using different techniques?

Struggling with initializing state in React / Redux. Before flagging this as a duplicate, I’ve already delved into the following resources: http://redux.js.org/docs/recipes/reducers/InitializingState.htm Redux - managing preload state What are your be ...

Experimenting with javascript through jasmine testing

I am new to Jasmine testing and would appreciate any help. I have an array of data that needs to be checked for existence. //result is an array of data. var availableTags = new Array(); function show(result) { var items = new Array(); ...

The contents of the multi-level navigation are automatically shown as the page loads

I've implemented a multilevel dropdown menu on my website using a plugin, and it works as expected. However, there's an issue where the contents of the dropdown menu display for a brief moment while the page is loading. I tried adjusting the posi ...

Mobile display exhibiting glitches in animation performance

I have implemented an animation in the provided code snippet. const logo = document.querySelector('.logo'); const buttons = document.querySelectorAll('.loadclass'); const html = document.querySelector('html') const cornerme ...

Executing iterative asynchronous calls in Node.js

As I delve into mastering Node.js, I've set up my application, defined routes, and created a controller. Currently, I'm working with an external API where I pass different IDs and need to compare the responses against specific values. To achieve ...

Looking for assistance with a JavaScript code snippet

I have encountered an issue while iterating through receipts in the given code snippet. The objective is to fetch the receipt number for each receipt and add it to a JSON object. However, I am facing a problem where the same receipt is appearing in two sep ...

Verify if data is correct before refreshing user interface

When attempting to submit the HTML5 form, it stops the form submission if any required fields are missing a value or if there is another error such as type or length mismatch. The user interface then shows highlighted invalid fields and focuses on the firs ...

Mocha avoids running the test

Hi everyone, I am a beginner in Node.js and JavaScript and I'm having trouble understanding why Mocha is skipping over my test. I know that I may not be using the request and supertest libraries correctly, but I really want to figure out why, when it ...