1

I have an ASP.NET MVC based website witch manages the database content and generate RSS files with View. But for output I use simple static HTML pages witch downloads content with a js file as code in blew:

$.get(RssRoot + '/instruments',function(datas){
$('item',datas).each(function(i) {
    var name = $(this).find("name").text();
    var thumbnail = $(this).find("thumbnail").text();
    var id = $(this).find("id").text();
    var href = Root + '/instrument.html?id=' + id;
    $("#instrument").append('<a href="' + href + '"><img title="' + name + '" class="image" src="' + thumbnail + '" /></a>');
});
});

Thumbnails are generating using this code:

public async Task<ActionResult> Instrument(Guid? Id = null)
{
    if (Id == null) return HttpNotFound();
    return File(db.Instruments.Find(Id).Thumbnail, "image/png");
}

You can see that images are not ftp files. They are loading from database. For example a thumbnail url for browser: ~/Thumbs/Instruments/fdbc870e-87a4-4d6e-befa-027af647f4ca

As you now, because this way has a behavior like lazy loading, I used it. But it has some problems such as downloading images every time. How can I cache images in browser for next use?

Note: I know that there are lots of plugins ready; But because my project is not standard as I said, this challenge is with it.

Why? I wanna reduce my database server traffic.

1 Answer 1

0

If you are looking to improve performance, consider adding the items to the <system.webserver> node of your web.config. These will enable object compression and cache static objects for 7 days:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
            <dynamicTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/javascript" enabled="true" />
                <add mimeType="application/javascript; charset=utf-8" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </dynamicTypes>
            <staticTypes>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/javascript" enabled="true" />
                <add mimeType="application/javascript; charset=utf-8" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="*/*" enabled="false" />
            </staticTypes>
        </httpCompression>
        <httpProtocol allowKeepAlive="true">
        </httpProtocol>
        <staticContent>
            <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
            <!-- IF PAGE STOPS LOADING CORRECTLY, REMOVE THE FOLLOWING MIME TYPE DEFINITIONS TO DEBUG -->
            <mimeMap fileExtension=".otf" mimeType="font/otf" />
            <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
        </staticContent>
1
  • Thanks for your attention my friend. I have an unprofessional hosting service witch gives my 25GB per month for data transfer. 100MB for files and unlimited for database. So I upload my images to database. But my 25GB is reducing fast. So I need to force browser to cache images. You can see app here.
    – Tayyebi
    Feb 24, 2015 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.