We're moving our website to new Cloud Load Balanced servers on Rackspace. It's all a bit of a new experience for us, we've ironed out most of the issues, apart from one.

We've set up the new servers to lsync from Server A to Server B (Server A is master).

From time to time we see css/js files 404. We can guess what's wrong, it's file syncing not happening fast enough between servers, and when a cache clear occurs on Server A, such as a cron run, then Server B is requesting the old CSS/JS files, and that request may go to Server A.

What is the proper way to set up Drupal 7 on load balanced servers so that CSS and JS files are in sync and don't cause 404?

  • 2
    Two years ago I had to deal with this issue and ended up writing a custom solution. I would be very interested to see if anyone else has got a better one. I suspect using a CDN so a file being deleted on the server doesn't invalidate the URL might be part of it. Commented Feb 3, 2015 at 11:43
  • 1
    @AlfredArmstrong thanks, for now we found a workaround using the Advanced Aggregation module, which can create aggregated css/js on the fly if it doesn't exist. Seems to be a decent solution.
    – Beebee
    Commented Feb 4, 2015 at 10:42
  • Ah, thanks, yes I think I used that as the basis for what I built, though it had some bugs then which have surely been fixed in the meantime. Commented Feb 4, 2015 at 11:43

2 Answers 2


Use csync2 / lsyncd to keep uploaded files (or all files) in sync.

An example configuration for Drupal can be found at http://www.severalnines.com/blog/scaling-drupal-multiple-servers-galera-cluster-mysql

Also, ensure your load balancer is configured for sticky sessions. In this way, if a user uploads a file or causes Drupal to generate new css/js files, those files will be served from the same server. Otherwise the files may be uploaded/generated to one server on a POST, but then another server may serve the response page before it gets the files.

We have used the above and had excellent production stability across three web-servers. We have about 100k+ nodes, ~40 content types, ~60 content providers, ~80k hits per day.

Originally I created a module which stalled Drupal page loads until file synchronizations completed, but we found it wasn't necessary.


Drupal's core aggregation does not work on a cluster because it creates the aggregates during the page rendering. Once the page is stored into the cache another server of the pool will read from the cache so it will not render the page again meaning that the CSS or JS aggregation will not be done locally.

To solve this problem, I created a NFS share between the servers just for the "css" and "js" folders. It was running ok for a while but under heavy load Drupal was sometimes generating empty files (2 servers creating the file at the same time). So even keeping in sync the servers is clearly not a solution.

But just as Beebee said, you can use the Advanced CSS/JS Aggregation module. This one is clever enough to be able to rebuild an aggregate just from the URL, because it stores in the database a mapping of the files that are part of the aggregate.

Advagg is also able to handle groups of aggregated files. This can reduce your bandwidth usage if your visitors navigate across different pages because the common files can be merged into a separate aggregate and the delta files merged into another aggregate.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.