How to reduce a unuse css file? - javascript

I am using bootstrap to build a mobile web page
only one page and use some of the bootstrap css and js code but I have to hold all the css and js.
since I only use some of it I want to reduce the unused css style and js code to reduce the file size
how to do it?
I mean if I only use the modal of the bootstrap how to reduce the css of col and alert and other css I do not used?

I'm not fully sure if this question really belongs here, but there is an answer to the question.
You can use Bootstrap's site to customize which elements of bootstrap you want and do not want, downloading a file with only the bits that you would like to keep.
This is available here: https://getbootstrap.com/docs/3.4/customize/

To read about it, go to their : https://www.labnol.org/internet/remove-unused-css/28635/

Remove Unused CSS from the Stylesheet
Here’s how you can easily find all the unused selectors in your CSS files in Google Chrome:
Open any page of your website inside Google Chrome and then launch the Dev Tools available under File -> Tools -> Developers Tools.
Click the Audits tab inside Dev Tools and select the “Web Page Performance” and “Reload Page and Audit on Load” options. Now click the “Run” button to begin the CSS audit process.
On the results page, expand the “Remove Unused CSS Rules” group and select the CSS file(s) that are linked from your site. You may ignore the CSS files added by social plugins and widgets since you do not have control over them.
Here you will get a sorted list of all styles that are defined in the CSS file but not used anywhere on the current page.
You can copy and save the results in a text file and repeat the steps for couple of other pages on your site. This is essential as not all selectors may be used on all pages. You can find the count of various selectors in the combined resultset, maybe using Google Sheets, and the selectors with the highest count can probably be “safely” removed.
read more this link

Chrome DevTools has coverage tool. It identifies which code is useful and which is not. I used it to reduce my css file from ~25K lines to ~2.3k lines.
Read more here: https://developers.google.com/web/tools/chrome-devtools/coverage

Related

How to display a leaflet map on a wordpress website?

I have finished a leaflet map on codepen.
My code is splitted in html/css and javascript/jquery.
I would like to know how to display the map on a wordpress website.
I had try the embedding on codepen, but the fact there is ''Result on top left'' and ''edit on Codepen'' doesn't match my needs.
Do i have to make the code in a full html (My javascript inside </>script then )?
Is there a easy way to display it?
Thank you very much
I use the following solution, which works for Elementor too.
Yes, do use the html, yet, add your css and js files inside your
wp-content > themes > child-theme > assets > css or js folders
link these files as you would in a standard html setting, either by typing up the whole permalink or in a shortened ../wp-content/etc. link. I use the first option.
Add your html and it should work.
Tip 1: Inside your browser, inspect for any errors, because if you have any older javascript , WordPress will issue a warning.
Tip 2: If you use any images, you need to optimize the images like WordPress Media does.

Remove specific Javascript code that causes high CPU usage from Tumblr theme

recently I decided to create a Tumblr using this theme
I'm a Firefox user, and I noticed that this theme slows down the browser a lot. After some investingation and asking, the culprit seems to be the possibility to add an animated particle background that, even when disable, causes high cpu usage.
This particle function is inside a script called "s.js", that contains other part of the theme.
Is there any way to clean up the code from everything related to this particle background, and still leave the theme functional?
Thanks
OK
Option 1:
Search for all of the libraries that are being called from the js file you linked to s.js apart from ParticleJS.
Images Loaded: https://unpkg.com/imagesloaded#4.1.3/imagesloaded.pkgd.min.js
Isotope: https://unpkg.com/isotope-layout#3.0.4/dist/isotope.pkgd.min.js
Infinite Scroll: https://unpkg.com/infinite-scroll#3.0.2/dist/infinite-scroll.pkgd.min.js
Fitvid: https://cdnjs.cloudflare.com/ajax/libs/fitvids/1.2.0/jquery.fitvids.min.js
Photoset grid: https://cdnjs.cloudflare.com/ajax/libs/photoset-grid/1.0.1/jquery.photoset-grid.min.js
Magnific Popup: https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js
Caveat, these are specific versions of each file and you could run into compatibility issues, if you need to link to a specific version.
Combine all the code from these files into a single file, then you could run it through a minifier: https://javascript-minifier.com/
For this solution to work you also need somewhere to host the file somewhere.
Option 2:
Link to all of the above files individually in your template. For example before the closing <body> tag you would need to add
<script type="text/javascript" src="https://unpkg.com/imagesloaded#4.1.3/imagesloaded.pkgd.min.js"></script>
... then add each of the other scripts. There may be a dependency order to these also, hopefully they are the same as in the header of the s.js file.
The drawback with this is instead of making a single http request to return a single js file, the template will request 6 separate js files (so this might be slower than the current system you have now).
Option 3:
If you can't host the file somewhere, you would have to actually copy the code from each js file into your template.

Difference between bootstrap.css and web.css file?

I was following this tutorial on Microsoft's developer network concerning using asp.net and mvc model with sql database. Here is the link to the tutorial that I was following
http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started.
So basically, I wanted to play around with the design of the file which is defined in these three files bootstrap.css, bootstrap.min.css, and web.css.
As to my understanding , bootstrap is an html, css, and javascript framework which has the design for the elements already defined. In Visual Studio, I began to edit the bootstrap.css file by changing background-color of the jumbotron element. However, when I saved the file and ran my web application , I noticed that the color remained the same and did not change. But, when I defined the design for the .jumbotron element in the web.css file, the element's background color changed accordingly to red.
Essentially, what I want to know is if bootstrap.css is restricted for editing within the template?
What is Bootstrap
I think you're trying to refer to the Twitter Bootstrap that is used all around the Internet. It contains most of the Styling techniques for the Elements, such as buttons, inputs etc.
When you edit a website's Stylesheet, (Bootstrap.css is a Style sheet and its name doesn't make it write/edit protected file) you get the style that you've applied to it.
http://getbootstrap.com/
Web.css
This file might be the default Style sheet that was created by the Developers at Microsoft while creating the Template for the Website that you're using.
Secondly, when you edit and create this file, it is also a Style Sheet which means it would apply the style to your website and all the web pages who are refering to it.
You're right. It has all the pre-defined methods and contains all of the contents and styles required to make a web page responsive. For more: https://en.wikipedia.org/wiki/Responsive_web_design
What might have caused this problem would be cache. When you first loaded the web page, it would have captured the New Style sheet from the file System and would have applied the styles. But second time it would have loaded the File from the Cache.
https://en.wikipedia.org/wiki/Cache_(computing)
This way, the browser would load the last successive layout of the Web Page. Without loading a new StyleSheet from the File System.
I really think, you need to reload the page using CTRL + F5 button. This would be helpfull in this manner! Because Bootstrap.css is editable and you can edit it. It doesn't prevent editing, only caching would be the problem here.

HTML file not working in Browser

I have created a simple - HelloWorld.html Webpage with HTML, JavaScript, CSS.
When I run it from Eclipse IDE, It works perfectly on browser.
What it does is like: the page has 5 buttons,
and hellow World is displayed from 5 different <div>'s
that remains hidden and appears as inline after button click.
When I navigate to the work-space and try to open the HelloWorld.html file in browser manually, nothing comes correctly.
All properties: positions and bgcolors etc declared in external css file has no effect on browser.
I know it sounds stupid, but I'm just hating myself for this.
Does anyone know why is it behaving in this way?
PS:
1. I have no Server-side scripting in the file.
2. HTML, JS, CSS are different file.
My best guess would be that you are trying to use the css file with a realtive path, which changes when you don't host it temporarily as eclipse IDE does.
First, open the developer toolbar (f12) & check the network tab to see if the css file is being loaded at all.
Try using an absolute path instead & see if it changes anything.
In my Exp. i have seen this kind of problems many times, the Inbuilt browser of eclipse some times does not support all features especially when you doing like designing purpose.
you can use MS-IE 6 or Above version for same.
or you can try some other browsers like:- Mozilla,Chrome etc.
because it has features for developers for scripting , div , css and many more . so u can check with them.
Thanks,
Arvind
It's because of file manager from which you have opened.
You just need to see the link in browser.
If it has a "content//:" in start then the css or JavaScript file you have linked in the HTML will not work.
What you need to do is change your file manager or create link manually.
To create a link manually you should use "file///:"in start for example if your file is in download then you should use something like that....
file:///storage/emulated/0/Download/My%20Web/index.html
Or you can use ZArchiver file manager and go to your file and use open with option to open file in browser.

Downloaded aspx website does not display well

I have downloaded a aspx webpage and saved it as html. I open it in IE and chrome and it takes time to load + some parts are missing. All the text is there but the onmouseover is not working properly and some css is not displaying correctly. Was the content not downloaded completely? i.e is it missing sme javascript, css or else?
I have done what you describe on many occasions for the purposes of putting together a prototype of new functionality in an existing application.
You will likely need to do a couple of things:
Ensure the paths to your JS and CSS resources are right (removing the unneccessary JS files, if any)
Also, you will likely need to update the paths in your CSS to any image resources in your page

Categories