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. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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-5Another solution I can think of is tearing down the huge
bootstrap.min.cssfile into multiple small files, say one file calledcommon.css, which contains definitions for common css elements like:root,@mediaqueries, 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.cssfile 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?
All reactions