Skip to content

Loading with async or defer #12

@hwhelchel

Description

@hwhelchel
    = javascript_include_tag 'application', async: Rails.env.production?

    css:
      #{CriticalPathCss.fetch(request.path)}
    javascript:
      loadCSS("#{stylesheet_path('application')}");
    link as="style" href="#{stylesheet_path('application')}" onload="this.rel='stylesheet'" rel="preload" /
    noscript
      link href="#{stylesheet_path('application')}" rel="stylesheet" /

If I load application.js async in production, and I require the loadCSS function in application.js, won't there be a chance it won't have loaded by the time the critical-path-css-rails is executed?

What's the most performant way to handle this use case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions