Skip to content

Use pre-compiled assets if available #288

Closed
@mchristen

Description

@mchristen

I've been trying to track down the cause of some request latency that happens on the first request after a fresh boot.

I determined that with the recent refactor of the server rendering code simply deferred the slowness to the first request instead of happening on bootup.

The issue is that by calling

::Rails.application.assets[filename].to_s

you are essentially calling find_asset on the Sprockets::Environment object. This causes the first lookup of the asset file to trigger a compilation to load the file into Sprockets cache objects.

In some production environments all assets are precompiled and config.assets.compile is set to false. I have a patch here that reads the file from disk if asset compilation is turned off in Rails. I'm sure there is a better way, and perhaps this should be a different kind of ServerRenderer altogether.

Using this patch I was able to get my first request latency down from 45s to around 4s, subsequent requests are much faster, what I would expect from a production system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions