Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm currently developing a web application and I was forced to use jQuery for some animations and other specific purposes, but still most of my code is written in JavaScript.
Should I rewrite these JavaScript modules if after all jQuery is being loaded every time? I know that in some cases it is better to use JavaScript instead of jQuery because it is faster and some other advantages but I'm already using jQuery throughout the page and I'm wondering should I use it everywhere instead of loading the whole library for few chunks of code.
Will there be any significant difference in the performance if the library is already loaded?
There won't be any difference, the Javascript speed is better. The performances wihout libraries still better. So keep your modules
Its up to you.
If you don't like to use any JS library, then you have code a lot.
The current jQuery v1.12.2(supports IE 6,7,8) size is 97kb. You use CDN version to reduce the loading time of it.
Will it affect the performance?? Yes, a bit it will do.
You didn't mention whether you are making any XMLHttpRequest;
if so, its better to use jQuery for better cross browser compatibility.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Lighthouse suggests that I need to remove the unused javascript from the third party javascript library say index.js . It is okay for this particular library to load after few 10 seconds once the page is loaded. So I used the SetTimeout method to do that but I don't think that is the right approach to do it.
Once I do that, lighthouse does not complain about unused javascript from this library and improves the score, but I am worried that in production Google measure the overall performance of the page from the moment page loads to the moment user leaves the page. So in that sense, the unused javascript is never removed and just delayed for the execution. People also suggested that lazy loading JS on user events will help but in our the case mentioned above, the JS should load automatically.
I am basically looking for the suggestion to:
How to handle the JS libraries that I can't get rid of and which has lot of unused code in the page?
Is setTimeout good solution for the above case?
Is my understanding of performance calculation by Google correct (in production environment) although it does not show unused JS after delaying for 10seconds?
I would be more than happy to get the answers.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
There are many ways to use JavaScript. When I use JavaScript with an anchor, I write code like this and I think this way is right.
Method One
But my co-worker uses JS like this.
Method Two
Is there a coding standard or are both methods correct?
DISCLAIMER: Inline JavaScript is, generally speaking, a bad idea, and 99% of the time you're much better off separating concerns, and using a library, such as jQuery, or whatever similar toolset that your framework of choice recommends.
Nonetheless, to answer your question, if you must use inline JavaScript, I recommend that you omit the "JavaScript:" keyword. It specifies a "pseudo-protocol," and is not necessary for modern browsers to interpret the code. It is a relic from the last decade, and there is a bug with some versions of IE:
"There is one (somewhat obscure) bug with the javascript protocol - in
Internet Explorer*, it will think you are leaving the page when you
click the link. If you are using window.onbeforeunload, then your
navigate-away message will appear at this time. For this reason alone,
we've stopped using the javascript protocol completely so we don't
have this bug show up because we forgot to check for it when we add a
navigate-away message to some page."
When do I need to specify the JavaScript protocol?
https://bytes.com/topic/javascript/answers/504856-javascript-pseudo-protocol-event-handlers
Both the ways are ok but in first way you should use a external JS file. Otherwise it is ok.
For small tasks and events second ways is good.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
From an experienced developer's perspective, is bad practice to create a web application using multiple JS frameworks ?
For example, if you start using AngularJS and if some tasks of the project can be done easier with JQuery, should you go for it, or try to make that part in Angular too ?
In my opinion, a framework should only be used if it's absolutly necessary. E.g if you do lots of DOM work, jQuery is the right one.
But, if you need a mvn framework, go for angular/backbone or something like this.
Tio many people today think that for each and every single problem, a framework is the best solution.
Sometimes, it could be the best solution to use 2 frameworks. E.g. jQuery + lodash.
So the answer is... It depends on the type of application you want to develop. My approach would be to allways ask whether the framework is really needed, or if you maybe just need a single function that you better could write on your own.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
As I am learning vanilla JavaScript right now, I don't always know what to ask when searching through JS documentation (mostly on Mozilla MDN). So, I use what I know in jQuery until I get there.
So, what performance or other drawbacks should I be aware of when using jQ to substitute for my lack of full JS understanding while I learn?
These days, clients run fast enough that you don't really need to worry about any performance differences between vanilla JavaScript and jQuery. Thus, it could be said that this is a sort of "premature optimization", so I give you the same answer I always give: Use what you know/what's easier to maintain until you can demonstrate a critical performance bottleneck via a profiler; only then should you figure out how to improve the performance, possibly including switching to vanilla JS.
You should learn to understand how to retrieve elements from the DOM and how javascript relates to HTML. Basically you are altering html-elements and attributes.
http://en.wikipedia.org/wiki/Document_Object_Model
http://www.w3schools.com/js/js_htmldom.asp
https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am looking to make a slightly responsive design. I was curious to know how people feel on loading a responsive design, should I load in a new css file and use JS to define the screen size. Or should I create media queries inside the current css file and just go from there. Looking for opinion on speed and what people feel is the more optimal approach.
Putting everything regarding styles in the CSS files is the best practice.
HTML => Structure
CSS => Styles
JS => Logic
The more you separate concerns, the easier your code will be to mantain.
As javascript might be disabled you should use CSS-only for the responsive purposes.
If you really can't do without javascript (for moving an element in the dom for example) make sure that you've got some fallback css for non-js-enabled users.
In fact very very few users will disable javascript, unless they are in emergency(say, if they only have outdated mobile phone because their new ones have run out of batteries). If your site is not toward these situations, use javascript without concerning that users will disable.
Generally, putting media queries in one css file will be a good choice if the file size is reasonalbe, since one file makes fewer request than seperated files.
Javascript, on the other hand, is the very fallback because old IEs do not support media queries.
You can refer to some frameworks such as bootstrap. An implementation outdoes all answers.