Replies: 2 comments 1 reply
-
As always that's a trade off between network request and size of script. https://datacadamia.com/web/browser/page_load#http_resource_request_optimization If you send properly your static resources with cache header, this hits only the first request. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Generates CSS for every page is bad idea - you not thinked how browser's cache it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let's all agree that having unused code in production is terrible, no one likes it, and it is a waste of resources; It will affect the loading time of a web page since the browser is required to fetch more data than needed. Therefore, there should be a way to pull only the necessary data upon request. However, implementing such a mechanism is a bit challenging, hence posting this in a discussion.
Right off the bat, I can think of having an api that handles requests and returns only the css elements needed for consumption. For instance, say we have the following endpoint:
https://bootstrap.com/css/?elements=
, a user can pull specific css elements like btn, btn-primary, mg-3, p-5, and the request becomes:https://bootstrap.com/css/?elements=btn,btn-primary,mg-3,p-5
Another solution I can think of is tearing down the huge
bootstrap.min.css
file into multiple small files, say one file calledcommon.css
, which contains definitions for common css elements like:root
,@media
queries, and things of that nature. This way, a user can pull specific css files stored on edge, cdn... For example, if a user wants to usebtn
, then they have to specify the name of the file in the head tag like the following:Another solution for this is to manually download and store the
bootstrap.min.css
file and adjust its content accordingly. However, doing such a task is hell since it requires scanning around 10k lines of css. I know that there are tools to automate such tasks. However, such tools will remove media queries and such; take the following as an example:Chrome coverage tool reported it as unused css. Therefore, it is not helpful to use such tools cause of false positives.
That is all i can think of at the moment. What do you think about such a problem?
Beta Was this translation helpful? Give feedback.
All reactions