What's new?!

  • Archive
  • RSS
  • Ask me anything

Performance Optimization Part 4: Amazon CloudFront

We decided to use Amazon S3 to store most of our larger files (mp3s, videos) rather than using the Sitecore Media Library.

Part of the performance optimization task was to create a new bucket on S3 called “cdn”. We then enabled Amazon’s CloudFront on that bucket.

This means that our static files (background images, scripts, css files) will all be served from a CDN, making the site faster for our domestic and specially international customers.

    • #performance
    • #amazon
    • #s3
    • #cloud front
    • #sitecore
  • 1 year ago
  • Permalink
  • Share
    Tweet

Performance Optimization: Part 1 (Images)

Part 1 of the performance optimization initiative was to reduce the overall size of the transfer.

A big chunk of what we are sending over HTTP were images (and still is). A big issue was our Slider banners. Those are big images (1020x287) and we have around 10 of them on our home page. Optimized versions have approximately 30kb while non-optimized were showing sizes of about 300Kb. Huge difference!

So what we’ve done?

First of all we exported all images from sitecore into the disk.

Then, we processed them through two different applications. For gifs and pngs we opted to use a unique format (PNG) and processed them through an amazing application called PNGOUT (http://advsys.net/ken/utils.htm). 

For JPGs we processed them through a similar lossless tool called purejpeg.

This was not enough. We had some banners that were saved as PNGs and were still too big. We then decided to go with JPG for all banners and larger images so part of the project was to convert certain images from PNG to JPG.

Another piece of it was to identifying images that were unnecessarily huge. A couple head-shots that were uploaded to our system had a full resolution so they had more than 1000px of width! All of them show in a control with 150px width only. So we re-sized and optimized those for web distribution.

To export the images we used a code that looks like this:

 var items =
Database.GetDatabase("master").SelectItems(
string.Format("fast://sitecore/media library/Images//*"));

Parallel.ForEach(items, item => {
try {
var filename = string.Format(@"C:\SITECORE_ALL_IMAGES\{0}.{1}",
item.ID.ToShortID(),
((MediaItem) item).Extension);
var stream = ((MediaItem) item).GetMediaStream();

using (Stream file = File.OpenWrite(filename)) {
CopyStream(stream, file);
}
}
catch (Exception) {

}

}
);

Then, to re-import the images after processing, we used a code that looks like this:

 var pngs = Directory.GetFiles(@"C:\SITECORE_ALL_IMAGES\PNG");
foreach (var png in pngs) {
try {
var mediaItem =
Database.GetDatabase("master").GetItem(new ID(Path.GetFileNameWithoutExtension(png)));
var m = MediaManager.GetMedia(mediaItem);
using (var stream = new FileStream(png, FileMode.Open)) {
m.SetStream(stream, "png");
}
} catch (Exception e) {
context.Response.Write(string.Format("error in {0} : {1}", png, e.Message));
}
}
    • #sitecore
    • #performance
    • #media library
  • 1 year ago
  • Permalink
  • Share
    Tweet

Community Preferences

We believe we addresses some issues that were seen in our “Engage with the Community” control.

Also, we now notify Community Managers of changes made by users in their profiles by email. This gives them a way to engage quickly with members that have shown interest in their community.

    • #cop
    • #sitecore
    • #usability
  • 1 year ago
  • Permalink
  • Share
    Tweet

Where is my format?

It’s tricky. Our AMS solution has an HTML editor that let’s users enter the brief and long descriptions of products. We did a project a couple months back that used the HtmlAgilityPack to clean the HTML. We had it all: word XML tags, font tags specifying size and type and the regular bolds (strong and b) and italics (i and em). To ensure the site had a consistent look and not a mix of a bunch of different fonts and sizes we opted to remove all HTML tags. Of course, sometimes editors purposely wanted Italics (like for book titles in descriptions) and those were being removed.

The way our process works is that we have a StoredProcedure that feeds a SOLR index (more on Solr later!). This stored procedure made use of a .NET CLR Scalar function that used a simple Regex to clean the HTML. That was the “StripHtml” function. Now, to support the new requirements, I added a new function called “CleanHtml” which just leaves <strong>, <b>, <i> and <em> tags. I’d like to use the AgilityPack for this as it’s a proper HTML parser but SQL doesn’t like it too much. So I just tweeked some Regex I found online.

Here is how the new SQL function looks like:

 [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString CleanHtml(string input) {
        try {
            var result = Regex.Replace(input, "<(?!/?(?:strong|b|em|i))[^>]*>", string.Empty, RegexOptions.IgnoreCase);
            return new SqlString(result);
        } catch (Exception) {
            return new SqlString(input);
        }
    }
    • #coding
    • #sitecore
  • 1 year ago
  • Permalink
  • Share
    Tweet

Gravatar and DISQUS

I really like Gravatar’s idea. A centralized and easy-to-use place to store your avatars and simple profile information.

Here we are using DISQUS premium which enables us to have Author-Specific email notifications and a seemless integration to our login system through their SSO.

Currently, we do not ask for images from members and Staff. So if they want their picture shown in comments they can easily set up a Gravatar account.

Gravatar works by using an MD5 hash of an email - so the integration was extremly simple.

Want to learn more about Gravatar? Check it out here.

    • #disqus
    • #sitecore
    • #gravatar
  • 1 year ago
  • Permalink
  • Share
    Tweet

Logo

About

Hi, my name is Flavio Silva and I'm a Solutions Architect at the American Society for Training & Development. In this blog I'll share some of the changes we've been making to our site.

I'll try to discuss different aspects of a sofware development life-cycle such as usability and software architecture.
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr