NashTech Blog

Optimizing Front-End Performance Using Bundles and CDNs for jQuery

Table of Contents

Optimizing Front-End Performance Using Bundles and CDNs for jQuery

Summary:
Many internal applications still depend on jQuery, plugins, and custom JavaScript functions. As pages grow, performance can degrade due to large script files and multiple network calls. This article explains how bundling, CDNs, and Azure Pipeline automation help optimize front-end performance in a maintainable way.


1. Why Front-End Performance Still Matters

Even in internal business systems, front-end performance affects daily productivity. Slow pages lead to:

  • Longer rendering time for complex screens
  • Blocking scripts delaying user interaction
  • Repeated downloads of the same libraries across pages

Because many enterprise applications continue to use jQuery-based UI components, it is important to apply modern optimization techniques without rewriting the entire front-end architecture.


2. What Are Bundles and CDNs?

✔ Bundling

Bundling combines multiple JavaScript files into a single optimized file. Instead of loading many small files, the browser downloads one or a few bundles.

Benefits:

  • Fewer network requests
  • Minified and compressed output
  • Easier cache control with versioned URLs

✔ CDN (Content Delivery Network)

A CDN hosts widely used libraries such as jQuery on servers distributed worldwide. Browsers often have cached copies from other websites, making loading faster.

Benefits:

  • Low latency delivery
  • Shared cache across different websites
  • Reduced load on your server

For many enterprise apps, the optimal approach is a combination: use CDN for common libraries and local bundles for internal JavaScript modules.


3. How Developers Commonly Use Bundles and CDNs

✔ 1. Load jQuery from CDN with Local Fallback

https://code.jquery.com/jquery-3.7.1.min.js
<script>
if (!window.jQuery) {
    document.write('<script src="/js/lib/jquery-3.7.1.min.js"></script>');
}
</script>

✔ 2. Bundle Custom jQuery Classes/Functions

Instead of loading many individual JS files:

<!-- Before -->
/js/app/dialog.js
/js/app/filters.js
/js/app/grid.js

You produce:

<!-- After bundling -->
/dist/app-bundle.min.js?v=20250101

✔ 3. Split Bundles by Feature Groups

An enterprise system may use separate bundles such as:

  • core-bundle.min.js — global helpers and common UI utilities
  • table-bundle.min.js — grid, sorting, filtering, export utilities
  • report-bundle.min.js — reporting-related UI logic

This ensures each page only downloads scripts it actually needs.

✔ 4. Use defer for Non-Critical Scripts

/dist/core-bundle.min.js?v=@Model.Version

This prevents blocking page rendering.


4. Example of a Reusable jQuery “Class” Stored in a Bundle

Custom utility modules become simpler when bundled:

(function(global, $){
    function FilterPanel($container, options){
        this.$container = $container;
        this.options = $.extend({}, options);
        this.init();
    }

    FilterPanel.prototype.init = function(){
        var self = this;
        self.$container.find('.btn-apply').on('click', function(){
            if (typeof self.options.onApply === 'function')
                self.options.onApply(self.collect());
        });
    };

    FilterPanel.prototype.collect = function(){
        return {
            keyword: this.$container.find('[name="Keyword"]').val()
        };
    };

    global.FilterPanel = FilterPanel;
})(window, jQuery);

Bundling allows these utilities to be reused across multiple screens with minimal per-page script.


5. How We Bundle JavaScript Through Azure Pipeline

We automate bundling and versioning inside our Azure DevOps CI pipeline. This ensures:

  • Consistent output for all developers
  • Automatic version stamping for cache busting
  • No manual file renaming
  • Security scanning of bundled code (SonarQube, Snyk, Gitleaks)

The process fits naturally into the Build stage.

✔ 1. Automatic Version Replacement in JS Files

Our JavaScript includes placeholders like:

var appVersion = "#{BuildVersion}#";

Azure Pipeline replaces this using PowerShell:

(Get-Content $_.FullName) -replace '#\{BuildVersion\}#', $version | Set-Content $_.FullName

This ensures all bundle URLs look like:

/dist/core-bundle.min.js?v=2025.11.29.1234

✔ 2. Where Bundling Fits in the Azure Pipeline

Azure Pipeline runs the following steps during build:

  • Gitleaks — detect leaked credentials
  • SonarQube — scan JS, CSS, C#, and Razor
  • Snyk — analyze JS dependencies
  • Replace JS version tokens
  • .NET Restore, Build, Test
  • CSS hashing for cache busting
  • Publish Web App

This guarantees that the bundled JavaScript that reaches production has been validated, versioned, and optimized.


✔ 3. How Bundled Files Are Produced

The project structure contains raw JS:

  • wwwroot/js/app/*.js
  • wwwroot/js/modules/*.js
  • wwwroot/js/shared/*.js

Our bundler (Webpack/Gulp/custom script) outputs:

  • /dist/core-bundle.min.js
  • /dist/table-bundle.min.js
  • /dist/report-bundle.min.js

The pipeline then inserts version parameters into these files so browsers always load the latest build.


6. Script Loading Flow (Text Diagram)

HTML Render
     ↓
Load jQuery from CDN
     ↓
If CDN fails → load local fallback
     ↓
Load core bundle (shared utilities)
     ↓
Load feature bundle (page-specific)
     ↓
Initialize jQuery modules on document ready

This hybrid approach avoids page blocking and reduces total download size.


7. Best Practices for Enterprise Teams

  • Use a CDN for common libraries like jQuery.
  • Bundle internal modules into logical groups.
  • Split bundles so each page loads only necessary code.
  • Avoid inline scripts except for initialization.
  • Always append version query strings for cache control.
  • Automate version replacement through Azure Pipeline.
  • Regularly remove unused legacy scripts.

8. Conclusion

Even without a full SPA architecture, front-end performance can be greatly improved using bundling, CDNs, and automated versioning. By integrating these techniques into our Azure Pipeline, we ensure that every deployment produces fast, clean, optimized JavaScript bundles for all users.

Picture of Dung Le

Dung Le

I am a Technical Lead with over eight years at the company, specializing in system migration, performance optimization, stabilizing legacy modules, and improving development processes. I enjoy solving complex problems, supporting team growth, and continuously learning new technologies to deliver better, more reliable solutions for the business.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top