Tag: Best Practice

Dockerfile Best Practice

Build Modular Images i.e. Decouple applications

Create a seperate image for each application. Containers can talk to each other and can form a single large application and helps to scale each application

Don’t sotre data in Images

Images are read-only layer. When a container or image is deleted the data is lost

Use Cache Busting strategy

Install the repositories and packages together. As the docker file ises layered architecture having a seperate command for updating repositories and packages may not gurantee the repsoitories will be upto date and may result in dependency issue.

Use Version Pinning

When installing packages specifiy which version you want to install as everytime the image is build it will install the latest package where a application may not be compatible. Version pinning will always ensure the image will have specific version which your application supports.

Create slim images

This will help pull the images from which ever repository you are using quickly

Install only necessary or required packages

This will make image slim or with minimal packages and no unwanted packages are installed so every time image is build with minimal packages the build is fast and light weight. Also the containers created from such images are light weight and fast.

Maintain different images for different environements

Development images may contain debug tools and temprorary files required for debugging and bulding your application. However there tools are not required for production images. Hence remvoe any temporary files/folder and such tools for prodcution by creating a seperate image for different environments.

Use multi-stage builds to create images

Multi-stage build helps to or uses multiple FROM statements where each FROM instruction can use a different base, and each of them begins with new stage of the build and everything that is required for application is in the final image leaving behind unwanted files. This will avoid executing any script that was done traditionaly.

Exclude any unwanted files and folders using .dockerignore file

Use .dockerignore to exlcude any unwanted files and folders e.g.:- temp folder etc. this make the image lighter.

Use CMD instructions to run software in Image

Use CMD instructions to run the software contained in your image along with arguments. CMD should be used in JSON format that is the command and parameters should be seperated by comma.

Minimize build times

By avoiding to send unwanted files to the build context using .dockerengine

References –

https://docs.docker.com/develop/develop-images/multistage-build/

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

Sitecore 10 SXA- Improve site performance by enabling Asset Optimizer

Asset optimizer helps improve the performance in production site by compressing/minifying the CSS and JS.

Minification of assets helps to cut the unnecessary portions of code and reduce the size of file to boost the performance by reducing amount of data over the internet.

Sitecore administrators can enable/disable optimizer globally of to a specific site.

Enable/Disable the Asset Optimizer globally

Enabling or disabling optimizer globally affects all the sites configured in the Sitecore instance.

To change the optimiser settings navigate to following location. This is accessible to Administrators-

/sitecore/system/Settings/Foundation/Experience Accelerator/Theming/Optimiser

You can also search “optimiser”-

If you can’t find this you may have to re-index master.

Select Scripts or Styles to change the settings

Modes of Optimizations

Concatenate And Minify Mode

When this option is selected. Sitecore will concatenate and minify the OOTB and Custom Scripts and Styles.

Example:- If you have a custom theme you can add the css files in your extension theme

This is in master database

Highlighted CSS is a extension to the base theme.

Web database when the page is first requested Sitecore will concat and minify all css in extension theme folder and create a optimised-min.css file

Styles loaded from the extension theme is concatenated and minified version with timestamp in query parameter (optimised-min.css)

Notice that the file name is optimised-min.css

Size of the optimized version is 367 KB
Concatenate and minified. Loads without comments

Concatenate Mode

Change the mode of optimization to “Concatenate”.

Web database now has optimized file created in extension theme

Styles loaded from the extension theme is concatenated version with timestamp in query parameter (optimised.css)

Notice that the reference to file is changed to optimised.css

Size of the optimized version is 381 KB
Concatenate but not minified. CSS loads with comments

Disabled Mode

Change the mode to “Disabled” and should see all the files loaded separately. Disabled mode is good for debugging but should not be used for production as it will give a performance hit.

CSS files are loaded separately and not concatenated nor minified

Best Practice – Enable Asset Optimizer in production environments

The same can be applied to the Scripts.

You have set the optimizer to concatenate and minify globally to your Sitecore instance but still don’t see the site been optimized.