1
import 'react-dates/lib/css/_datepicker.css'

The css above is not critical, so I can defer loading it.

How to defer loading css when using import?

google gives me how to do it using <link>

4
  • i am not sure but let see if this is helpful. medium.com/webpack/… Commented Mar 16, 2020 at 7:18
  • Its important to know where is this import, if its on root components, or on some component that can be imported dynamically itself Commented Mar 16, 2020 at 9:02
  • is there others CSS you import along side this CSS, or it the only CSS in this component Commented Mar 16, 2020 at 9:03
  • This is in some component which is not always rendered (I guess that satisfied can be dynamically imported) @CaptainMhmdrz_A , there are other '*.js' files I import Commented Mar 16, 2020 at 10:24

1 Answer 1

1

If you are using webpack, you can use its dynamic import feature:

const delay = () => import(`react-dates/lib/css/_datepicker.css`)
setTimeout(() => delay(), 0)
Sign up to request clarification or add additional context in comments.

1 Comment

I just don't understand why Webpack loaders can't detect dynamic imports and automatically add a style tag with the defer attribute, but that setTimeout hack does it! Thanks

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.