.NETヘルプ WebGrease .NET Core(開発者向けの仕組み) Curtis Chau 更新日:6月 22, 2025 Download IronPDF NuGet Download テキストの検索と置換 テキストと画像のスタンプ Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article WebGrease's integration with IronPDF and .NET Core offers a potent method for producing high-quality PDF documents and streamlining web application performance. With the use of JavaScript compression, image optimization, and CSS minification, WebGrease is a feature-rich package that makes websites run quicker and smoother for developers. Developers can easily create dynamic PDFs from several sources, including HTML and MVC views, by using IronPDF, a powerful .NET toolkit for producing and manipulating PDF documents. Web applications are kept fluid and adaptable with this integration, enabling effective resource management and dynamic PDF generation. WebGrease and IronPDF are fully compatible with .NET Core, allowing developers to create cross-platform applications that function flawlessly on Linux, macOS, and Windows. This results in an enhanced user experience thanks to optimized performance and superior document handling. What is WebGrease? Originally created as a component of the ASP.NET stack, WebGrease is a tool for automating processes such as optimizing JavaScript, compression, picture optimization, and CSS minification of static files in order to improve web performance. These optimizations contribute to the reduction of web resource sizes, which improves web application performance and speeds up load times. In the context of .NET Core, when we discuss WebGrease, we mean the application of these optimization methods to .NET Core applications. Microsoft created the cross-platform, open-source .NET Core framework to let developers create cutting-edge, scalable, and high-performing apps. Developers can apply performance optimization techniques from traditional ASP.NET applications to their .NET Core projects by integrating WebGrease. This way, developers can make sure that their web applications are efficient and performant on various platforms, such as Windows, Linux, and macOS. Features of WebGrease Within the framework of .NET Core, WebGrease provides a number of capabilities targeted at enhancing the effectiveness and speed of web applications. The salient characteristics are as follows: CSS Minification: Eliminates extraneous formatting, comments, and whitespace from CSS files. Reduces HTTP requests by combining numerous CSS files into a single file. Enhances performance and speeds up loading times for CSS. JavaScript Compression: Minimizes JavaScript files by removing unnecessary characters. Combines multiple JavaScript files into one. Reduces JavaScript file size to expedite download and execution times. Image Optimization: Compresses images without significantly reducing quality. Converts images to more efficient formats when appropriate. Optimizes image resources to increase loading speeds. HTML Minification: Removes whitespace and comments from HTML files. Simplifies HTML files for quicker browser parsing and rendering. Resource Bundling: Combines several JavaScript and CSS files into a single file. Reduces the number of HTTP requests needed to load a page, improving load times. Configuration Flexibility: Provides options for configuring the optimization process. Allows developers to choose which directories and files to optimize or exclude. Cross-Platform Compatibility: Fully compatible with .NET Core, allowing use on Windows, Linux, and macOS. Ensures performance improvements work well in various environments. Integration with Build Processes: Can be integrated into build procedures to automatically optimize resources during deployment and development. Supports automated processes to ensure consistent optimization across development phases. Improved Performance: Minimizes the resources that must be loaded, thereby improving overall web application performance. Enhances the user experience and speeds up page loading. Create and Configure WebGrease To use WebGrease in a .NET Core application, install the necessary packages, configure the build process, and set up optimization tasks. The following steps will help you establish and set up WebGrease in a .NET Core application: Create a .NET Core Project First, create a new .NET Core web application. You can use the .NET CLI for this purpose. dotnet new web -n WebGreaseApp cd WebGreaseApp dotnet new web -n WebGreaseApp cd WebGreaseApp SHELL Add Required Packages Although there isn't a direct .NET Core package for WebGrease, you can achieve similar functionality with other programs like BundlerMinifier. Add this package to your project. dotnet add package BundlerMinifier.Core dotnet add package BundlerMinifier.Core SHELL Configure Bundling and Minification Create a bundleconfig.json file in your project root to provide the bundling and minification settings for your CSS and JavaScript files. Here is an example configuration. [ { "outputFileName": "wwwroot/css/site.min.css", "inputFiles": [ "wwwroot/css/site.css" ], "minify": { "enabled": true, "renameLocals": true } }, { "outputFileName": "wwwroot/js/site.min.js", "inputFiles": [ "wwwroot/js/site.js" ], "minify": { "enabled": true } } ] Integrate with the Build Process Add instructions to execute the bundling and minification operations during the build process in your project file (.csproj). Add the following element inside the <Project> element in your .csproj file: <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Exec Command="dotnet bundle" /> </Target> <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Exec Command="dotnet bundle" /> </Target> XML Install and Run BundlerMinifier To use the BundlerMinifier tool, you must install the .NET utility. Execute the following command: dotnet tool install -g BundlerMinifier.Core dotnet tool install -g BundlerMinifier.Core SHELL To bundle and minify your files, run: dotnet bundle dotnet bundle SHELL Optimize Images You can use ImageSharp or other .NET Core-compliant image optimization tools for image optimization. Install ImageSharp Install the SixLabors.ImageSharp package: dotnet add package SixLabors.ImageSharp dotnet add package SixLabors.ImageSharp SHELL Here is an example of a code snippet for image optimization: using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using System.IO; public void OptimizeImage(string inputPath, string outputPath) { // Load the image using (var image = Image.Load(inputPath)) { // Resize and optimize the image image.Mutate(x => x.Resize(new ResizeOptions { Mode = ResizeMode.Max, Size = new Size(800, 600) })); // Save the image in an optimized format image.Save(outputPath); // Automatic encoder selected based on file extension. } } using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using System.IO; public void OptimizeImage(string inputPath, string outputPath) { // Load the image using (var image = Image.Load(inputPath)) { // Resize and optimize the image image.Mutate(x => x.Resize(new ResizeOptions { Mode = ResizeMode.Max, Size = new Size(800, 600) })); // Save the image in an optimized format image.Save(outputPath); // Automatic encoder selected based on file extension. } } Imports SixLabors.ImageSharp Imports SixLabors.ImageSharp.Processing Imports System.IO Public Sub OptimizeImage(ByVal inputPath As String, ByVal outputPath As String) ' Load the image Using image = System.Drawing.Image.Load(inputPath) ' Resize and optimize the image image.Mutate(Function(x) x.Resize(New ResizeOptions With { .Mode = ResizeMode.Max, .Size = New Size(800, 600) })) ' Save the image in an optimized format image.Save(outputPath) ' Automatic encoder selected based on file extension. End Using End Sub $vbLabelText $csharpLabel Run your application to ensure bundling and minification are operating as intended. Open your application in the browser, then verify that the JavaScript and CSS files are minified. By following these steps, you can set up and configure WebGrease-like optimization for a .NET Core application using tools compatible with the current .NET environment. IronPDFを始めよう Setting up performance optimization for your web resources and using IronPDF for PDF generation and manipulation are both necessary for integrating WebGrease-like optimization with IronPDF in a .NET Core application. Here's how to get started, step-by-step: IronPDFとは何ですか? The feature-rich .NET library IronPDF allows C# programs to produce, read, and edit PDF documents. With this program, developers can easily convert HTML, CSS, and JavaScript information into high-quality, print-ready PDFs. Among the most crucial tasks are adding headers and footers, dividing and combining PDFs, adding watermarks to documents, and converting HTML to PDF. IronPDFは.NET Frameworkと.NET Coreの両方をサポートしているため、さまざまなアプリケーションに便利です。 Because PDFs are user-friendly and include extensive content, developers may easily incorporate them into their products. Because IronPDF can handle complex data layouts and formatting, the PDFs it generates as an output closely mirror the HTML text originally provided by the client. IronPDFの機能 HTMLからのPDF生成 Converts JavaScript, HTML, and CSS to PDF. Supports media queries and responsive design, aligning with modern web standards. Useful for dynamically decorating PDF documents, reports, and invoices using HTML and CSS. PDF編集 Allows the addition of text, images, and other content to existing PDFs. Extracts text and images from PDF files. Merges multiple PDFs into one. Splits PDF files into separate documents. Includes watermarks, annotations, headers, and footers. PDF変換 Converts a wide variety of file formats to PDF, including Word, Excel, and image files. Allows PDF to image conversion (PNG, JPEG, etc.). 性能と信頼性 High performance and reliability, suitable for industrial applications. Handles large document sets with ease. IronPDFをインストールする .NETプロジェクトでPDFを操作するためのツールを手に入れるために、IronPDFパッケージをインストールしてください。 dotnet add package IronPdf dotnet add package IronPdf SHELL Configure Bundling and Minification Ensure that the bundleconfig.json config file is in place to provide the bundling and minification settings again as needed: [ { "outputFileName": "wwwroot/css/site.min.css", "inputFiles": [ "wwwroot/css/site.css" ], "minify": { "enabled": true, "renameLocals": true } }, { "outputFileName": "wwwroot/js/site.min.js", "inputFiles": [ "wwwroot/js/site.js" ], "minify": { "enabled": true } } ] Connect to the Building Process Ensure that your .csproj file contains instructions for executing the minification and bundling operations during the build process. Add the following Target within the <Project> element: <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Exec Command="dotnet bundle" /> </Target> <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> <Exec Command="dotnet bundle" /> </Target> XML Integrate IronPDF Build a controller with IronPDF to produce PDFs. Create a new PdfController controller. using Microsoft.AspNetCore.Mvc; using IronPdf; namespace WebGreaseIronPdfApp.Controllers { public class PdfController : Controller { public IActionResult GeneratePdf() { // Create a PDF from a simple HTML string var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a generated PDF document.</p>"); // Save the PDF to a byte array var pdfBytes = pdf.BinaryData; // Return the PDF file as a download return File(pdfBytes, "application/pdf", "example.pdf"); } } } using Microsoft.AspNetCore.Mvc; using IronPdf; namespace WebGreaseIronPdfApp.Controllers { public class PdfController : Controller { public IActionResult GeneratePdf() { // Create a PDF from a simple HTML string var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a generated PDF document.</p>"); // Save the PDF to a byte array var pdfBytes = pdf.BinaryData; // Return the PDF file as a download return File(pdfBytes, "application/pdf", "example.pdf"); } } } Imports Microsoft.AspNetCore.Mvc Imports IronPdf Namespace WebGreaseIronPdfApp.Controllers Public Class PdfController Inherits Controller Public Function GeneratePdf() As IActionResult ' Create a PDF from a simple HTML string Dim renderer = New ChromePdfRenderer() Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello, IronPDF!</h1><p>This is a generated PDF document.</p>") ' Save the PDF to a byte array Dim pdfBytes = pdf.BinaryData ' Return the PDF file as a download Return File(pdfBytes, "application/pdf", "example.pdf") End Function End Class End Namespace $vbLabelText $csharpLabel The first thing we do in the PdfController code is import the required namespaces, which are Microsoft.AspNetCore.Mvc for ASP.NET Core MVC functionality and IronPDF for PDF generation. Because it derives from Controller, the PdfController class is an MVC controller. The GeneratePdf method in this class is defined to manage the creation of PDFs. To convert HTML material into a PDF, this function creates an instance of IronPDF's ChromePdfRenderer. A basic HTML string can be transformed into a PDF document using the RenderHtmlAsPdf function. The BinaryData attribute is then used to save this PDF to a byte array. Lastly, the PDF file is returned as a downloadable response using the File method, along with the requested filename (example.pdf) and the correct MIME type (application/pdf). The program can now dynamically create and serve PDF documents based on HTML content thanks to this integration. Route to Generate PDF Make sure that the PDF generation routing is included in your Startup.cs file. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "pdf", pattern: "pdf", defaults: new { controller = "Pdf", action = "GeneratePdf" }); }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "pdf", pattern: "pdf", defaults: new { controller = "Pdf", action = "GeneratePdf" }); }); } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel Run and Verify Run your application to ensure that you can create PDFs and that the bundling and minification are functioning properly. dotnet run dotnet run SHELL Open the browser and navigate to your application. It should be possible for you to navigate to /pdf and download a PDF document. 結論 IronPDF and WebGrease-like optimization combined provide a potent combo for improving online performance and producing high-quality PDF documents in .NET Core applications. Developers can ensure their applications are efficient and flexible by using tools like IronPDF for creating PDFs and BundlerMinifier for optimizing resources. In addition to picture compression, resource optimization strategies like CSS and JavaScript minification also help to speed up page loads and enhance user experience. Concurrently, IronPDF has strong capabilities for dynamically creating PDFs from HTML text, simplifying the process of creating well-prepared documents like invoices, reports, and more. This integration provides a complete solution for contemporary web development needs within the .NET Core framework, not only improving online application performance but also adding useful features for processing PDFs. With IronPDF and Iron Software, you can enhance your toolkit for .NET development by taking advantage of OCR, barcode scanning, PDF creation, Excel connectivity, and much more. Starting at a competitive price, IronPDF offers developers access to more web apps and features, along with more efficient development, by combining its core concepts with the highly flexible Iron Software toolbox. The well-defined license options for the project make it easy for developers to select the optimal model, assisting in prompt, well-organized, and efficient execution of solutions for a wide range of issues. よくある質問 .NET Coreでウェブアプリケーションのパフォーマンスを最適化するにはどうすればよいですか? .NET CoreでWebGreaseを統合することで、JavaScript圧縮、画像最適化、CSS最小化を提供することによってウェブアプリケーションのパフォーマンスを強化できます。これらの技術はリソースサイズを減少させ、ロード時間を加速し、効率とユーザーエクスペリエンスを向上させます。 .NET CoreアプリケーションでHTMLからPDFを生成する利点は何ですか? IronPDFを使用して.NET CoreアプリケーションでHTMLからPDFを生成することで、開発者はウェブコンテンツから直接印刷準備が整ったドキュメントを作成できます。これは、レポート、請求書、他のドキュメントを動的に生成するのに理想的で、元のHTMLのフォーマットを保持します。 .NET Coreアプリケーションで動的PDFをどのように作成できますか? IronPDFを使用して.NET Coreアプリケーションで動的PDFを作成できます。HTMLやMVCビューを高品質のPDFに変換し、元の構造とデザインを維持したドキュメントの生成を可能にします。 .NET CoreアプリケーションにPDF生成を統合するプロセスはどのようになりますか? .NET CoreアプリケーションにPDF生成を統合するには、IronPDFパッケージをインストールし、アプリケーションで必要な設定を構成し、RenderHtmlAsPdfのようなIronPDFのメソッドを使用してPDF生成ロジックを実装し、HTMLコンテンツをPDFに変換します。 WebGreaseはどのように.NET Coreアプリケーションのパフォーマンスを向上させますか? WebGreaseは、CSSとJavaScriptの最小化、画像の最適化、リソースのバンドリングなどの最適化プロセスを自動化することで.NET Coreアプリケーションのパフォーマンスを向上させます。これらのプロセスはリソースサイズを減少させ、ロード時間を短縮し、アプリケーションの効率を向上させます。 LinuxやmacOSでWebGreaseとIronPDFを使用できますか? はい、WebGreaseもIronPDFも.NET Coreに対応しており、LinuxやmacOSを含むさまざまなオペレーティングシステムでその機能を利用できます。Windowsでも使用可能です。 .NET CoreでIronPDFを使用する際の一般的なトラブルシューティングシナリオは何ですか? .NET CoreでIronPDFを使用する際の一般的なトラブルシューティングシナリオには、すべての依存関係が正しくインストールされていることを確認し、構成設定を検証し、プロジェクト内の他のライブラリまたはパッケージとの競合を確認します。 IronPDFの文書生成の主要機能は何ですか? IronPDFの主要機能には、PDFドキュメントの生成、読み取り、編集、HTMLやさまざまなファイル形式のPDFへの変換、複雑なデータレイアウトの維持が含まれ、.NET Coreアプリケーション内で高品質なドキュメント処理を保証します。 IronPDFはPDF変換のためにHTMLコンテンツをどのように処理しますか? IronPDFはHTMLコンテンツを高品質のPDFに変換し、元のHTML構造を忠実に再現します。これにより、結果のPDFがソースコンテンツのレイアウト、スタイル、フォーマットを忠実に維持することを保証します。 .NET Coreアプリケーションで画像処理を最適化する方法は? .NET Coreアプリケーションでの画像処理を最適化するには、ImageSharpのような画像最適化ツールを使用し、品質を大幅に損なうことなく画像を圧縮し、より効率的なフォーマットに変換することを検討してください。これにより、全体的なアプリケーションのパフォーマンスが向上します。 Curtis Chau 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 関連する記事 更新日 9月 4, 2025 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む 更新日 9月 4, 2025 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む 更新日 8月 5, 2025 C# Switch Pattern Matching(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む DuckDB C#(開発者向けの仕組み)Azure.Messaging.ServiceBus Example ...
更新日 9月 4, 2025 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む
更新日 9月 4, 2025 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む
更新日 8月 5, 2025 C# Switch Pattern Matching(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む