-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage as render-blocking script #20
Comments
Hello @kctdfh, The flash that you see happens because your CSS does not use the dark mode at the time you load the DOM.
That is a normal behavior as you are trying to apply changes and reference DOM elements before the DOM is loaded. If you want to link the library in the head of your document you can use the Feel free to ask if you encounter other issues, have a great day. |
Hey @ColinEspinas Thank you for taking the time. I was already using variables but made the following changes that eliminated the flash for subsequent page visits. There's still an even shorter stutter when you visit the page with a cleared cache but that's really not an issue. I'll leave my solution here for anyone who may be interested in the future:
The combination of the above measures have fully eliminated the stutter/flicker. They may not all be necessary but the overall load time improvements is an added bonus anyways. Thanks for making this simple and feature-complete framework 🙏 |
I am happy that you've eliminated your flicker issue, I didn't mention it in my previous answer but it obviously is better to link the script to initialize darken as soon as the DOM is loaded and to keep your latency low as this might impact non-cached styles. All your points seems to make sense to me and I didn't know that the redirection made by unpkg was that slow. You've made a really great job to go through all the possibilities and I think your answer will help a lot of people passing by, thanks a lot. As you might seem to have resolved your issues I'll close this issue, do not hesitate to open another one if you need supplementary help. I am happy to hear that you like this little project, have a great day. |
Is your feature request related to a problem? Please describe.
My issue is that every new page always loads in light mode initially. Meaning that there's a very short flicker when the browser renders the light mode before finding out the user wants dark mode. This makes the implementation look a little unprofessional and is actually annoying when using the site in total darkness.
Describe the solution you'd like
I've looked around and it seems that the solution would be to initialize the dark mode and do all the checks in a script tag placed in
<head>
. This way, the check is blocking the render for a few extra milliseconds until it figures out the right theme.Describe alternatives you've considered
I tried to place my
darkmode = new darken(options, callback)
function in the<head>
right after calling the CDN but the browser saysUncaught TypeError: Cannot read property classList of null
which occurs 3 times (lines 31, 36, and 96 of the prettified Chrome console).My
options
object doesn't set a toggle target nor a container as the DOM is not rendered yet. So I don't know what the issue is.Additional context
Any other solution that could help me eliminate the flicker would also be appreciated! Cheers
The text was updated successfully, but these errors were encountered: