In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
[editor's note] the author is the most valuable blogger (MVB) Jonathan Danylko in the DZone community, and mainly introduces ten ways to speed up ASP.NET MVC applications. Compiled and presented by domestic ITOM management platform OneAPM, the following is the text.
Everyone wants to keep abreast of the latest news.
I mean, people can't wait to predict the headlines of the next day. No one likes to wait.
Wait in line, wait at a red light, wait to open a web page, wait, etc.
Of course, no one likes to wait for the page to load slowly, especially when the mobile side visits the site. In fact, the sensitive nerves of Web developers determine whether we wait or not.
Now, fast response is not only from the requirements of users, but also the main factor that determines the ranking of Google search. In addition, Google also vigorously promotes the Google AMP program to make the website load faster.
Considering that most websites have speed problems, I would like to use this article to help Microsoft developers optimize their websites.
In this article, the author will introduce ten ways to speed up ASP.NET MVC applications.
1. Application caching
Caching has always been a tried and tested last resort in optimizing applications. Caching can definitely speed up the application as long as it is used properly.
When making database calls to retrieve records, it is the best time to implement application caching.
For example, you set up a blog. When a visitor requests a blog post, you retrieve it from the database and save it in the cache. When the next visitor requests the same blog post through ID, the application first looks for the blog post in the cache based on ID, and if it finds it, it returns it to the visitor without having to access the database.
This saves the high cost of database calls.
Extended reading: to achieve efficient and fast websites by adding a simple cache layer
two。 Optimize picture
Before, I have never known how much a picture will account for in a blog post. Sometimes, depending on the content of the article, the picture may be the biggest resource in a blog post.
You should compress these huge resources. The smaller the picture, the faster the page will render.
The Image Optimizer (Picture Optimization) plug-in is a useful Visual Studio plug-in. Select all your images and choose either Lossless or Lossy image optimization mode, and each image will be compressed at a certain rate.
In addition, if you master front-end client tools such as Grunt or Gulp, you can automatically optimize images when creating or deploying applications.
Extended Reading: Visual Studio 2015 Picture Optimization plugin
3. Use Sprites
Every website has pictures. Pictures are almost an essential element of the website.
But what if you have a lot of small pictures? Suppose there are 20 small images, that is 20 image retrieval requests, one for each picture.
At this point, Sprites can come in handy.
Sprites is a large picture made up of many small pictures. The browser can directly request the large image, and then you can capture the small image through CSS technology and display it in different locations on the web page.
I know that many developers are not familiar with CSS. Therefore, it is recommended that you find some materials to study hard. CSS is really useful.
In addition, there are many online sprite generators that can assist in this process. (Piskel, Sprite Cow, or Google search: "online Sprite generator")
Extended reading: ASP.NET MVC: data-driven CSS Sprites
4. ETags
Some readers may not know what ETags is. In fact, ETags is a tool for Web cache validation, allowing conditional client requests.
With ETags, browsers can determine whether a resource is needed. If not, the browser does not send requests to the Web server, minimizing the number of requests.
The author even listed the ETag ActionFilter class as my favorite ActionFilter class, because ETags does minimize the number of requests sent by the website to the Web server.
Extended Reading: my five favorite ASP.NET MVC ActionFilters
5. Bind or minimize JavaScript/CSS code
Bundling and minimization are no longer new concepts.
Bundling is the process of packaging all JavaScript and CSS code into a JavaScript or CSS file. This is similar to Sprite technology, but deals with JavaScript and CSS files. Bundling reduces costs by reducing requests for separate JavaScript and CSS files.
JavaScript and CSS files are filled with spaces that take up a lot of space. Minimization is the process of removing a large number of spaces in a JavaScript or CSS file.
In the ASP.NET MVC project, there is a BundleConfig.cs file under the App_Start folder. You can define bundling or minimization settings for JavaScript and CSS files in this file.
Extended Reading: binding and minimization
6. Compress
Have you found out our tricks?
There are two ways to achieve compression: one is to activate compression through IIS, and the other is through the ActionFilter class.
When compression is enabled, the Web server compresses the resources into packets and then passes them on to the client. The latter decompresses and then displays the content.
This can effectively improve the speed of resource transmission.
The author also wrote a CompressFilter class for this purpose. By calling this class through the Action method, you can compress the web page.
Extended Reading: my five favorite ASP.NET MVC ActionFilters
7. Minimize HTML
In the previous discussion of minimization, I can't help thinking that there must be a lot of spaces on your HTML page.
The smaller the HTML file, the faster it can be transferred to the browser. Depending on the size of the HTML page, removing spaces can reduce the size by 20 to 50 percent.
To this end, the author wrote a Whitespace ActionFilter class, which is also one of my favorite ActionFilter classes.
Extended Reading: my five favorite ASP.NET MVC ActionFilters
8. Use AJAX as much as possible
AJAX has been launched a long time ago, and there are many benefits. It blurs the line between desktop applications and Web applications.
It can also definitely speed up some tasks on the site.
For example, the author has set up a dashboard in his own website.
In the implementation, I can first have the page load a dashboard skeleton. After the page is loaded, you start running the JavaScript method to request the widget to load. Where the widget appears later, you can first place the icon waiting to be loaded. When the assembly is loaded, replace the icon waiting to be loaded with the contents of the assembly.
This can make the user's browsing experience more smooth.
Extended Reading: why AJAX is like Pepper
9. Minimize database calls
Object-relational mapping (Object-Relational Mapping, ORM) databases such as Entity Framework and NHibernate can make implicit calls (hidden calls), even if you never ask for such calls.
Every ORM database has many little-known "traps". However, what you can do is to make sure that you only make one database call each time you retrieve data in your code.
When I first started using Entity Framework database, I suffered a lot of losses. For example, to retrieve a particular record, I made a database call. When retrieving the record, the program found the sub-objects of the record and decided to retrieve them. For this reason, another database call was made for each entity (sometimes, for a particular record, 200 database calls were made. It's terrible! ).
Now, the author's rule of thumb is:
Determine whether you need one record or multiple sets of records.
If only one record is needed, use the repository (repository) to get the record.
If you need more than one or more sets of records, use sproc (stored procedure, Stored Procedure).
If you're not sure how to get multiple result sets, you can read posts about using Entity Framework to retrieve multiple result sets.
Extended reading: ASP.NET MVC: using Entity Framework to return multiple result sets from a generic repository
10. Use reliable third-party services as much as possible
Remember what I said earlier about using AJAX as much as possible?
For the same reason, I decided to give up creating a custom comment system and use Disqus instead.
Why? There are five reasons:
Disqus is free.
Disqus requires only a small piece of JavaScript code and basic access methods (Basic Access Method
BAM), you can immediately implement a comment system.
After the deployment is successful, the web page loads first, while the Disqus loads in the background. Usually, because the comments section is often located at the bottom of the page, users will not see the comments section when they first open the page.
Disqus is also friendly when loading on the mobile side.
Disqus comes with some social networking attributes that allow users to see comments on articles on the Disqus site.
Such third-party services not only provide common basic functions for my website, but also provide a smooth reading experience for my readers with the help of AJAX.
Extended reading: Disqus
Conclusion
Most of the speed improvement methods described in this article require specific programming skills. Once you have mastered these skills, you can easily achieve an efficient and fast website.
All of the above technologies are applied to the author's website.
You don't believe me?
Right-click to view the source code for this article.
OneAPM can help you easily lock .NET application performance bottlenecks and analyze them layer by layer through powerful Trace records, until you lock the line-level problem code. The response speed of the system is displayed from the user's point of view, and the user usage is counted by region and browser dimension. To read more technical articles, please visit OneAPM's official blog.
This article is from the official OneAPM blog.
Original address: https://dzone.com/articles/10-ways-to-speed-up-your-aspnet-mvc-application
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.