Everybody needs information fast.
I mean, they need it recently. No one likes to wait. Waiting in line. Holding up for a red light. Waiting, waiting, waiting.
So actually, we do not like holding up for our web pages to load especially on our mobile devices. The nerve of web developers making us wait.
Not only does your audience want your site to be quick, it’s presently one of Google’s essential ranking components. Besides that, they spawned an activity with their Google AMP pages to make the internet indeed quicker.
It’s a big issue with most websites so I thought this would be a great post to help Microsoft developers in optimizing their website.
Nowadays, I cover ten ways to speed up your ASP.NET MVC application.
1. Application Caching
Caching is one of those programming techniques that should be used as a final resort, but it certainly quickens your application when utilized legitimately.
One of the excellent place to put application caching is when you make a database call to retrieve records.
Let’s say you have got a blog. When a person requests a particular post, you pull it from the database and put it in the cache. The next person who requests that same post by Id, the application will look for the post id in the cache and in case it finds it, returns it without hitting the database.
It highly saves the costly access of a call to the database.
2. Optimize Your Images
I didn’t ever knew how much space images take up on a blog post. Depending on the post content, they are the biggest asset within the post.
You wish to shrink a few of those suckers. The smaller you make the images, the quicker the web page renders.
One of the good add-on to Visual Studio is the Image Optimizer Addon. Select the images you need, choose Lossless or Lossy image optimization, and the images will be optimized with a rate of the savings for each image.
Moreover, once you master front-end client-side tools like Grunt or Gulp, you can automatically have your images optimized after you build or deploy.
3. Use Sprites
Every site has images. They are a necessity.
But what happens when you have a lot of tiny images? In case you have got 20 little images, that’s 20 requests for retrieve each image.That’s where sprites come in.
Sprites are images inside a larger image. The browser makes a ask for that one large picture file and you use CSS to grab the images and display them on the webpage.
Now, I know when I specify CSS to developers, they glaze over. I would suggest looking at a few resources and learning it. It is unquestionably profitable.
In any case, there are online sprite generators that help with this process (Piskel, Sprite Cow, Google: “Online Sprite Creator”).
For those pondering what they are, ETags are utilized for web cache validation which permits conditional client requests.
It’s a way for the browser to distinguish when a resource isn’t required and won’t make a request to the server to drag it minimizing requests.
I’ve even included an ETag ActionFilter as one of my favorite ActionFilters. It certainly makes this site minimize requests to the server.
Bundling and minification came into existence for a while.
Can you see a design here?
There are two ways to do this. One way is to activate compression through IIS and the either way is through an ActionFilter.
When enabled, the server will compress the resources into one bundle and send it down to the client. The client uncompresses the package and shows the content.
This speeds up the transfer of the assets.
I also wrote a CompressFilter for such a task. Put this on top of an Action Method and you’ll have compression capabilities for that page.
7. Minified HTML
While talking about minification, I too realized that your HTML page contains a lot of spaces in it.
The littler the HTML, the speedier it’s delivered to the browser. Depending on the measure of the HTML page, expelling spaces can decrease the HTML by 20-50%.
There’s too a Whitespace ActionFilter I wrote which is additionally one of my favorites.
8. Use AJAX When You Can
AJAX came into existence for a while and for great reason. It obscures the distinction between a desktop and web application.
It can definitely speed up certain tasks on a website.
For illustration, I’ve built one or two dashboards in my time.
This gives the user the point of view that the site is quick and gives them time to focus on things that have changed on the dashboard while the widgets are upgrading.
It’s makes the audience’s experience more enjoyable.
9. Minimize Database Calls
ORM (Object-Relational Mapping) libraries like Entity Framework and NHibernate can make hidden calls even in spite of the fact that you never issued them.
There are a lot of gotchas with each ORM, but one thing you’ll do is confirm in your code that only one call is made to pull back the data you wish.
I’ve been burned by Entity Framework a number of times when I to begin working with it. I would make a call to retrieve a specific record. Whereas retrieving that record, it would see the child objects and choose to retrieve those as well making another database call…
My basic rule of thumb now is:
Decide if I require a record or numerous sets of records.
In case I require one record, I utilize a repository to drag back a record.
In case I need more than one or multiple result sets, I use a sproc (Stored Procedure)
In case you’re unsure about how to drag back numerous result sets, check out the post on using Entity Framework to retrieve multiple result sets.
10. Use third-party services where they make sense
Keep in mind when I said utilize AJAX where it makes sense? This was my approach when I decided to discard a custom commenting framework and utilize Disqus.
Why? Five reasons:
Disqus is free.
Disqus contains a social networking viewpoint to it allowing others to see the comments regarding the post on Disqus’s site
This third-party service enhanced my site with common functionality and provides a fast, AJAX-enabled experience for my readers.
A majority of these speed improvements are coding-specific. You’ll effectively implement these procedures to create your site shout.
All of these procedures are utilized on my website.
Do not believe me?
Right-click and see the source of this post. This executed the Whitespace ActionFilter.