Performance: CORS configuration
CORS configuration affects the browser's ability to load resources from different origins, impacting page load speed and interaction readiness.
Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins 'https://trusted.example.com' resource '/api/*', headers: :any, methods: [:get, :post, :options] end end
Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*' resource '*', headers: :any, methods: [:get, :post, :options] end end
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Wildcard origins with broad resource access | Minimal | 0 | Low but delayed by network | [X] Bad |
| Restricted origins and resource paths | Minimal | 0 | Low and fast | [OK] Good |
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'https://example.com'
resource '*', headers: :any, methods: [:get, :post]
end
end
What happens if a request comes from 'https://evil.com'?Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :put]
end
end
But PUT requests from frontend are failing with CORS errors. What is the likely problem?Pass the test and this pattern moves unknown