Hello Sling Devs,

I pushed in a library prototype for automatically optimizing files (for the
moment mostly images) in the Sling whiteboard repository[1]. The need
solving here is if you are creating a website with a Sling-based
application you want to save bandwidth by optimizing all of the images on
the site, but optimizing images requires another 3rd party tool such as
ImageOptim, PngCrush, ImageMagic, etc. Instead, it'd be great if you could
just optimize the images (and other files as well) right in the CMS.

With the FileOptimizer, you could create something like what I created for
Sling CMS:

Before Optimization Screenshot - https://imgur.com/PjLVmzv
After Optimization Screenshot - https://imgur.com/Ut43PxZ

The FileOptimizer Library uses the whiteboard pattern to allow developers
to register FileOptimizer instances. Each FileOptimizer will optimizes one
or more file types by getting a stream of data and optimizing that data.
The library handles:

   - Ensuring the file has not already been optimized
   - Finding the right FileOptimizer for the file type
   - Making sure that the optimization actually resulted in a smaller file
   - Storing the results of the optimization

The library also includes:

   - A Sling Model for previewing an optimization
   - A Sling Model for seeing the data from an optimized file
   - Two Sling Post Servlet Operations, one to optimize the file, one to
   revert to the original
   - Servlets for getting a preview / data for an optimization
   - An OSGi Event handler (disabled by default) to automatically optimize
   files
   - A FileOptimizer for PNG files using
   https://github.com/depsypher/pngtastic
   - A FileOptimizer for JPEG files using a configurable compression level

I'm very interested in your opinions about this module and if there are any
suggestions / recommendations.

A few specific points:

   - Right now the library uses a separate namespace (optim) for all of
   it's properties and mixins, does that seem acceptable or should these be
   moved into the sling namespace?
   - The servlets are registered under /system/fileoptim, is there a better
   path?
   - Any suggestions / improvements for performance / features

Regards,
Dan

[1] - https://github.com/apache/sling-whiteboard/tree/master/file-optim

Reply via email to