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.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35