Book Image

Instant Galleria How-to

By : Nathan Van Gheem
Book Image

Instant Galleria How-to

By: Nathan Van Gheem

Overview of this book

Providing beautiful and usable galleries is an important aspect of the Web today. A gallery solution needs to integrate into your web application easily and seamlessly. Users expect mobile sites that function on par with their desktop counterparts‚Äîespecially for image galleries. In order to accomplish these tasks, you need to use a JavaScript (not Flash) that is extensible and scales to mobile devices. "Instant Galleria How-to" will teach you how to use Galleria in advanced scenarios to become an expert and integrate Galleria into your next project using themes and plugins to accomplish any task. This book teaches you how to use and create themes and plugins,  using the Galleria API through a series of recipes that include a plethora of code examples. You'll be taken through detailed instructions on the usage of JavaScript to customize Galleria. You will create your own theme (mobile friendly), plugin, and learn all the configuration options of Galleria. You'll learn how to customize Galleria by using its extensive API, optimize Galleria, integrate with Google Analytics, create tests for your customization, and integrate into your web application. You'll become an expert user of the Galleria framework, which will enable you to deploy beautiful, mobile friendly galleries for your next web project.
Table of Contents (7 chapters)

Optimizing Galleria (Simple)


This recipe discusses optimizing Galleria by using various methods that help to improve the performance of Galleria.

Getting ready

Since this recipe is just discussing various techniques to improve the performance of Galleria, we'll not use a specific example to walk through. The following techniques can be applied to any of the galleries created throughout the book.

Image sizes

For images deployed to a website, always use sizes complementary to the size of the gallery. If the image is drastically larger than the gallery, a visitor to the site will be downloading larger images than what is necessary and this can slow down the performance.

Providing thumbnails

Always provide thumbnails for galleries as we've done so far in this book. Thumbnails are much smaller versions of the original images that are shown in the carousel. Galleria will only preload (a parameter that can be customized) a couple of non-thumbnail images ahead of time; however, if no thumbnail is provided, all of the larger images will be loaded since the thumbnails will always be shown.

The ideal thumbnail size will depend on the size utilized in the theme.

Optimizing resources

Always use minified versions of JavaScript and CSS resources on live sites so visitors are only required to download the smaller version of the files. A minified version of a resource is one where the contents of the file are optimized for small file sizes. Galleria ships with minified versions of all its resources—these are resources with filenames that end with .min.js or .min.css.

In addition, merge multiple JavaScript and CSS resources into single files. The advantage of this is that a site visitor has fewer requests to make for resources before it can finish rendering a page.

Some CMS platforms, such as Plone, will provide this merging and minification automatically. So if you are developing in those platforms, make sure CSS and dependent JavaScript resources are merged along with the rest of the site's resources.

Galleria size

For dynamically loading Galleria images, it is not advised to create large galleries (those over 30 images). Especially for non-modern browsers, this can affect performance. In the following recipe, we'll discuss how to dynamically load more images as the gallery is being browsed.

Web server

Modern web servers provide features that help improve website performance. For example, make sure to enable compression on assets being delivered by your web application. Most web servers, for example Nginx and Apache, support gzip compression by default. In addition, make sure to configure your web server to set appropriate cache headers.

Resource minification

There are free online tools for minifying resources to use if minification is not provided on the utilized platform. For CSS, tools are available at http://www.minifycss.com/. For JavaScript, tools are available at http://www.minifyjavascript.com/.