9-15-2025

 Visited Bundling again.

https://www.debugbear.com/blog/make-fewer-http-requests
https://www.debugbear.com/blog/render-blocking-resources
https://stackoverflow.com/questions/36517829/what-does-multiplexing-mean-in-http-2
unicode

CssRewriteUrlTransform

TYpe of content that can be preloaded

https://gemini.google.com/app/74af011b549ef661
https://claude.ai/chat/c5690923-6693-413a-a9e8-3e05e4ddb206
=========

Here is a summary of our entire conversation, formatted for your daily learning log:

Summary of Web Performance Optimization in ASP.NET MVC

This log details a step-by-step process of diagnosing and fixing web performance issues in an ASP.NET MVC 5 application, focusing on client-side optimizations.

1. Initial Diagnosis: The Problem with Load Time

  • Symptom: A high load time (24.14 seconds) and a high number of HTTP requests (75).

  • Key Insight: The huge gap between DOMContentLoaded (2.77 s) and load (24.14 s) points to a significant delay in downloading and processing client-side resources (CSS, JS, images), not a server-side bottleneck like TTFB (Time to First Byte).

2. The Core Bad Practice: Individual File Loading

  • The Issue: The application was loading dozens of CSS and JavaScript files with individual <link> and <script> tags. Each file requires a separate HTTP request, leading to network overhead and queuing.

  • The Solution: The System.Web.Optimization library in ASP.NET MVC is specifically designed to solve this with bundling and minification. This combines multiple files into a single, optimized file, drastically reducing HTTP requests and file size.

3. Correcting the Implementation (The Iterative Process)

  • Bundle Configuration: A BundleConfig.cs class was used to define logical groups of files (bundles). Initially, the dynamic path ~/Brands/@ICS360.Models.Utility.BrandCode/css/brand.css caused an error because the bundling engine requires static paths. The solution was to load this file separately.

  • Relative Path Bug: A common 404 error for font files occurred because the bundling engine did not correctly rewrite relative CSS paths. The solution was to apply the CssRewriteUrlTransform class, which is designed to fix this issue.

  • Bundle Naming: A NullReferenceException was caused by a mismatch between the bundle name used in @Scripts.Render() and the name registered in BundleConfig.cs. The solution was to ensure the names were an exact match.

  • File Content Error: A low-level ArgumentOutOfRangeException was identified, indicating a problem with the content of a specific file (sweetalert2.js), likely caused by a corrupted download or an encoding issue. The recommended fix was to re-download a fresh copy of the file.

4. The iframe Optimization

  • The Issue: An iframe was being loaded with the initial page, incurring a performance cost even if the user never interacted with it.

  • The Solution: Implement lazy loading. The best method was to dynamically create the iframe with JavaScript only when the user clicked the button to open it. This ensured that the iframe's content was loaded on-demand, moving the network cost from the initial page load to a later interaction.

5. Overall Takeaways

  • Bundling is key. Reducing the number of HTTP requests is the single most impactful client-side optimization.

  • Be meticulous with file paths and names. Small errors in bundling configuration can lead to hard-to-debug runtime exceptions.

  • Lazy load non-critical resources. Don't load content that isn't immediately needed.

  • The CssRewriteUrlTransform is essential when bundling CSS with relative paths to assets.

  • The System.Web.Optimization framework can be buggy, so using robust coding patterns (like creating a bundle object and then adding transforms to it) is a good defense against framework-specific issues.
    ===========

MVC 5 Bundling and Performance Optimization - Learning Summary

Initial Problem

  • Started with a CSS bundling issue where CssRewriteUrlTransformFixed was causing compiler errors. The original code had syntax and path issues that prevented proper CSS bundling.

Key Issues Discovered

1. CSS Bundling Path Problems

    • Root cause: Bundle virtual paths didn't align with actual file structure
    • Symptom: 404 errors for fonts and icons (Material Icons, Kendo UI fonts, Bootstrap icons)
    • Solution: Aligned bundle virtual paths with file locations:
      • Bootstrap bundle: ~/assets/css/bootstrap/BootstrapCss
      • Custom CSS: ~/assets/css/CustomCss
      • Kendo CSS: ~/assets/plugins/kendo-material/KendoCss
      • Plugins CSS: ~/assets/plugins/PluginsCss

2. Third-Party Performance Impact

    • Problem: iframe with src="https://eu.bubble365.app" was loading immediately on page load
    • Impact: Added 4+ external requests to initial page load, significantly slowing performance
    • Solution: Implemented lazy loading - iframe only created when user clicks the floating button
    • Result: Considerable improvement in load times

3. JavaScript Bundling Challenges

    • Attempted: Bundling page-specific scripts to reduce 73 total requests
    • Issue encountered: ArgumentOutOfRangeException during bundling
    • Root cause: sweetalert2.js file causing minification/bundling errors
    • Debugging approach: Isolated problematic file by testing bundles incrementally

Technical Concepts Learned

CSS Bundling Best Practices

    • Bundle virtual paths should match file directory structure for relative path resolution
    • Separate bundles by file location when CSS files reference different relative assets
    • MVC 5 handles basic URL rewriting automatically in most cases

JavaScript Bundling Considerations

    • Dependency order matters (jQuery must load before jQuery plugins)
    • Some files may contain modern syntax incompatible with older minifiers
    • Page-specific bundles work better in layout files using sections rather than individual views

Performance Optimization Principles

    • Defer non-critical third-party content using lazy loading
    • Bundling reduces HTTP requests but doesn't bundle static assets (fonts, images)
    • Font preloading should be applied selectively, not broadly

Practical Outcomes

    1. Reduced HTTP requests: CSS bundling reduced ~13 individual CSS files to 4 bundles
    2. Fixed asset loading: Fonts and icons now load correctly due to proper path alignment
    3. Improved initial load performance: Lazy-loaded iframe eliminated external requests from critical loading path
    4. Systematic debugging approach: Learned to isolate issues by testing components incrementally

Key Takeaway

  • Bundle virtual paths acting as the "apparent location" of CSS files is crucial for relative path resolution - a fundamental concept that applies to any web bundling system, not just MVC.

Comments

Popular posts from this blog

Group deletion

Chart.JS does works if parent is hidden(), and CPU issue

Powershell Azure UserGroups Removal