-
Notifications
You must be signed in to change notification settings - Fork 48
Will RequestReduce sync css, javascript and sprite image files accross all of the web servers in my web farm?
Not by default. The default configuration simply saves the sprite and minified css and scripts to your server's local disk. If you have multiple servers serving your content, this could have some undesirable consequences assuming that you consider image and css 404 errors as undesirable. I do. The initial http request that requests the base page html may return a css url that has been processed by RequestReduce. There is no guarantee that the next request that fetches this css file will come to the same server and that server may not have processed the css quite yet and will therefore return a 404 error and the user may have a very strange looking page. This risk continues until every server has processed the the original css and javascript. This might be a short window of time and the urls generated on each server will be identical. However, if you run a professional web site that serves from more than one server and would like to ensure that such an experience never occurs, you have two options.
##File Replication You can continue to use RequestReduce's [LocalFileStore] (RequestReduce Configuration Options) strategy as long as the [physical directory] (RequestReduce Configuration Options) where RequestReduce saves its files is replicated to all web servers. Both rsync and the recent versions of Microsoft's DFS are capable of facilitating this.
##Sql Server Storage You can [configure] (RequestReduce Configuration Options) RequestReduce to save its generated files to a sql server database that all of your web servers can immediately access. If you are worried about the performance impact of a database call per css, javascript and image fetch, RequestReduce takes measures to minimize this impact. First, RequestReduce sets [aggresive cache expiration headers] (https://github.com/mwrock/RequestReduce/wiki/Will-browsers-cache-the-css%2C-javascript-and-image-files-that-RequestReduce-serves%3F) on all css, javascript and images it serves to ensure that a browser will not ask for the css, script or image file again. Don't worry, if you change your css, scripts or images, RequestReduce employs strategies to make sure browsers get a new copy right away (you might need to [flush] (https://github.com/mwrock/RequestReduce/wiki/How-can-I-get-RequestReduce-to-refresh-changed-CSS%2C-scripts-or-images%3F) RequestReduce to trigger the change). Furthermore, when RequestReduce pulls an image, script or css from the database, it will cache this file on disk and serve all subsequent requests from the disk cache.
To configure RequestReduce to store its files in the database:
- If you have installed RequestReduce via Nuget, you will also need to install RequestReduce.SqlServer via
Install-Package RequestReduce.SqlServer
, otherwise if you have downloaded the zip package, add a reference to RequestReduce.SqlServer and the EntityFramework Dlls. - Set RequestReduce's contentStore setting to SqlServerStore and its connectionStringName to either the connection string of your database or the name of the <connectionStrings> element you would like to use.
- Set RequestReduce's storePollInterval setting to an interval (in milliseconds) that RequestReduce should check for CSS reductions processed by other servers in your cluster. If this is not specified, RequestReduce will still remain in sync accross servers but every server will have to process the css and background images on its own. By using this setting, you allow one server to download the processed css and images and thereby save some CPU cycles on all other servers. Unless your site is under heavy load, processing the css separately on each server should not be a large concern.
- Execute the RequestReduceFiles.sql script to create the RequestReduceFiles table used by RequestReduce. This file is located in the RequestReduce.SqlServer folder of the zip download file and also in the Tools folder of the RequestReduce.SqlServer Nuget packlage.
- Make sure that the appropriate permissions are set on this table so that your web server's account or the sql account in your connection string has read and write access.
Here is an example RequestReduce configuration section for a sql server installation:
<RequestReduce connectionStringName="server=(local);database=mydatabase;trusted_connection=Yes" contentStore="SqlServerStore" storePollInterval="60000" />