Open Closed

How to remove a JavaScript or CSS file from the bundle in MVC? #184


User avatar
0
alper created
Support Team Director

How do I remove the jquery.js from the bundle?


1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    There are standard bundles come from the framework itself. These are CSS and JavaScript bundles. You can get list of these files and remove/add. Open BookStoreWebModule.cs In ConfigureServices() method, add the below code

       Configure<AbpBundlingOptions>(options =>
                {
                    options
                        .ScriptBundles
                        .Configure(StandardBundles.Scripts.Global, bundle => {
                            bundle.AddContributors(typeof(RemoveJqueryScriptContributor));
                        });
                });
    

    And add this class,

    public class RemoveJqueryScriptContributor : BundleContributor
            {
                public override void ConfigureBundle(BundleConfigurationContext context)
                {
                    var jquery = context.Files.FirstOrDefault(x => x.EndsWith("jquery.js", StringComparison.InvariantCultureIgnoreCase));
                    if (jquery != null)
                    {
                        context.Files.Remove(jquery);
                    }
                }
            }
    

    This code removes jquery.js from the standard global scripts bundle.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 16, 2025, 12:13