Limit the scripts on the page to only those from utilized plugins

Can we optimize the HTML output by including only the necessary scripts and files used on the site/page?

The page speed is significantly affected by loading all JS and CSS files for installed plugins and the admin interface, as seen in the example below:

var ip = {"baseUrl":"http:\/\/localhost\/ImpressPages\/","safeMode":false,"languageId":1...

Thank you, Morten

Answer №1

In the realm of plugins, each one has the power to dictate which assets are loaded with each page request. However, there is an opportunity for you to craft your own plugin that adheres to your unique logic and can eliminate certain assets before the page is displayed (consider utilizing the ipBeforeController event for this purpose). The designation of _1 signifies a low priority level, ensuring that your script will be executed last in the sequence.

class Event
{
    public static function ipBeforeController_1()
    {
        // Retrieve all JavaScript files that have been added
        $allJs = \Ip\ServiceLocator::pageAssets()->getJavascript();

        // ... insert your custom logic here ...

        // Remove specific file
        \Ip\ServiceLocator::pageAssets()->removeJavascript($fileName);
    }
}

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

ScriptManager is not accessible in the current ASP.Net Core Razor Page context

I'm facing an issue where I have a view (such as Index.cshtml) and a page model (like Index.cshtml.cs). In the view, there's a JavaScript function that I want to call from the OnPost() method in the page model. I tried using ScriptManager for thi ...

Please be aware that any fabricated comments will not be displayed in the posts object

-I have made an EDIT at the bottom of my original post -For my plunker, please visit this link Currently, I am learning AngularJS by following a tutorial located here. At this moment, I am stuck on the step called 'Faking comment data'. I have ...

Is the custom comparator in AngularJS filter not functioning properly with null values?

[New Version] I've discovered a solution to address this issue - by utilizing AngularJs version 1.3.6 or higher, items with null properties will not vanish after applying a filter and then removing it! original query below Hello everyone, I am curre ...

Bootstrap badge is encountering loading issues

My index.html isn't displaying the badge correctly on any browser. The numbers aren't showing up in a colored circle, it looks like the CSS didn't load properly. I've tried using both local and CDN paths for bootstrap and jquery, but t ...

The hover effect on the menu button is not covering the entire button when the screen is resized

It appears that I am encountering a problem with the hover functionality. When my screen is at full size, hovering over a menu option causes the entire background color to change. However, upon resizing the screen, only a part of the background color chang ...

What is the best way to adjust Material UI Grid properties according to the screen size?

I am working with Material UI and have a grid on the homepage that needs to maintain certain properties regardless of screen size. However, I want to apply a negative margin when the screen reaches 1200px or larger (lg). Currently, the grid is set up like ...

Embed the website onto a webpage using ajax or an iframe without any need for navigation

I have a unique challenge ahead. Imagine there are two websites, one is a web page and the other is hosted within the same domain. My goal is to load the entire second website into a div or iframe of the first web page, similar to how a free proxy browser ...

Achieve Dual Functionality with Vue.JS Button within a Parent Element

My parent component structure looks like this: <template> <b-container> <b-modal id="uw-qb-add-item-modal" ref="uw-qb-add-item-modal" title="Enter Item Number" @ok="handleNewItem"> <f ...

What could be causing a successful return from JQuery Ajax but still showing an error in Firebug within a PHP application?

I'm encountering an issue with my form submission and jQuery validator plugin. Everything seems to be working fine until I reach the submit handler in my jQuery code: submitHandler: function (form) { $.ajax({ type: "POST", url: ...

Switch the secondary menu to be the main menu on all pages excluding the homepage in WordPress

I am looking to customize my menu display by showing the primary menu only on my home page (front-page.php) and displaying the secondary menu on all other pages except for the home page. In my functions.php file, I have registered both the primary and sec ...

Compilation of CSS by Webpack resulting in peculiar class identifiers

Currently, I am using webpack for developing a React app with a NodeJS backend. I've encountered an issue with styling the app as webpack seems to be interfering with my CSS, causing changes in class names. For example, in my base.css file, I have d ...

Create an array by grouping objects together using a specific key to form a new array object

Here is my array object: [{ role : 'Role 1', name: 'A', slid: 'a'}, {role : 'Role 1', name: 'B',slid: 'b'}, {role : 'Role 2', name: 'X', slid: 'x'}, {role : 'Ro ...

What is the alternative method for locating a button element in Selenium when it doesn't have an ID, Value, or Type attribute

<button class="btn" style="designs">CLICK ME</button> What is the method to locate this specific element on a web page with Selenium and PhantomJS? ...

Discover the joy of reading with wrap/unwrap to consume more content in less

I am experimenting with a 'read-more read-less' feature using a wrap method that currently only works for the 'show more' functionality. So, to clarify, if the text exceeds a certain length, I truncate it and insert a read-more-link ( ...

Angular JS: Implementing a click event binding once Angular has completed rendering the HTML DOM

Exploring AngularJS for the first time, I've researched extensively but haven't found a satisfying solution. My goal is to retrieve data from the server and bind it to HTML elements on page load. However, I also need to bind click events to these ...

How to Safely Merge Data from Several Excel Files into a Single Worksheet in Google Sheets using ExcelJS without Overwriting Existing Data

Just to clarify - I'm not a seasoned developer, I'm still a newbie at this. My current challenge involves transferring data from multiple Excel files located in one folder to a single worksheet in Google Sheets. To do this, I am utilizing excelJ ...

Using JavaScript to parse JSON data containing additional curly braces

Looking at this JSON object: var dataObj = { data: '\n{ sizeMap:{\nxSizes: "REGULAR|SMALL", \ncurrItemId: "",\ncurrItemSize: "",\nmanufacturerName:"Rapid",\npartNumber: "726G", \nsuitStyle: "R",\nhasSC: "",&bso ...

What are some effective methods for optimizing GLSL/C code in Three.JS when using PerObject-Blur?

UPDATE 2 I have successfully integrated custom attributes using THREE.js. Each pass in the vertex shader is now aligned with the position attribute, resulting in an efficient solution with minimal code. An example will be added later UPDATE 1 This me ...

Approach to dividing PHP output into multiple outputs (AJAX, PHP) (nested AJAX requests, AJAX inside AJAX loop?)

Seeking advice on how to efficiently handle PHP output in small chunks for AJAX responseText. The project involves a webpage using AJAX to input a last name, which is then processed by a PHP program. The PHP code randomly selects three people with differen ...

"Create a flexible CSS grid with a dynamically changing number of rows and customizble

I am currently working on a project that involves creating a dynamic grid layout with two resizable columns, namely #red-container and #green-container. The goal is to make each column resizable horizontally while also allowing the main container #containe ...