Open Closed

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


0
alper created
Support Team

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


1 Answer(s)
  • 0
    alper created
    Support Team

    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.