performance of dom element vs jquery object [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
which one is faster
document.getElementsByName('tempName')[0].value
or
$('[name="tempName"]')[0].value
I want to know because I'm writing js codes were I have to use it for around 10 thousand times on every change of a single field and I want to know its effect on performance.

The first one seems to be faster. Using pure javascript.
Tested with jsperf: http://jsperf.com/performance-fsdfsd

Pure JavaScript should work faster here. So this one is
document.getElementsByName('tempName')[0].value

The first one. No doubt about it. Not a single test needed for that.
However, the questions you should be asking yourself is:
By how much?
Does it really matter?
How big is your app that you worry about these things?
Is it worth sacrificing readability & cross-browser support for such a tiny gain?
If you can make do without jQuery as a dependency, then you can save yourself & your users some precious bytes. But, if you anyhow need jQuery elsewhere on the page, I don't think fiddling like this is gonna make a real-life difference.
Bottom line: you should test your real-world example, not just this one abstract line. The vanilla JavaScript might be faster, but if it makes no difference to your app, then why bother?

Related

Similar and simplified examples (newbie questions) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm currently studying about web development, I still don't know about jquery, but I've a little knowledge about javascript, html and css (basic).
I've been looking at some examples in github to improve my skills, and I've found this content;
https://github.com/stewilondanga/editables
I perfectly understand the theory, but I do not know how to put it into practice, I would like for any similar examples (simplified alternatives) and how to convert the exported code generated by javascript into a html5 table?
Any example would be appreciated! thanks for your attention!
First of all, jQuery does not generate code. It's a framework, you load it into a web page, and then you can use it from within Javascript code in that page.
I suggest you start by looking at the source of https://stewilondanga.github.io/editables/, if an editable tables is what you need. There are more general frameworks to do this, e.g. Aloha
To try it yourself, I'd suggest you bite the bullet equip yourself with some kind of web server, be it on a server somewhere, or on your local machine, so you can easily try out things like this, copy the sources, alter the code etc.., and quickly hit reload on your browser.
While it may seem easier to run a local server and point your browser at http://localhost/something, IMHO it also takes more tinkering to get browsers to embrace that fully. You don't need the extra grief while already learning all those new concepts. If you want to tackle this seriously, consider getting a hosting service or small VPS somewhere. If you don't know how to do that, get help for that first, but get it out of the way. It'll save you much grief.

How can i pack javascript via php like javascriptobfuscator.com [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
if i put below javascript in javascriptobfuscator.com
Before
var a="Hello World!";
function MsgBox(msg){
alert(msg+"\n"+a);
}
MsgBox("OK");
it returns below packed javascript
After
var _0xd429=["\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x21","\x0A","\x4F\x4B"];
var a=_0xd429[0];function MsgBox(_0xdb32x3){alert(_0xdb32x3+_0xd429[1]+a);};
MsgBox(_0xd429[2]);
how can i make same functionality in php.
Static asset minifying and file merges are accomplished automatically in many web frameworks (in Rails this concept is called the "asset pipeline"). You need to use a framework that has an asset minification/compilation scheme that suits you, otherwise either
use a build tool that watches your codebase and executes automatically if you change any files
write a build script and execute it yourself when creating a build
Assetic seems to be a PHP tool of choice that does all this for you.
https://github.com/kriswallsmith/assetic
Also, Asset Pipeline/Framework for PHP
I beg the question
Why do you want to secure your javascript?
Just making it unreadable to humans does not mean someone with aspbergers or with enough motivation to deobfuscate it cannot.
If you are protecting your script because you don't want people to recycle it, then minify (manually or automatically through frameworks and plugins).
If you have other security concerns then I think your time is better spent elsewhere
Sorry if this sounds harsh but I wasted a lot of time on this before realizing how futile and useless this endeavour turned out to be

Moving objects inside the browser [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to display in a browser a web page which contains:
a number of objects with predictable shapes (squares, rectangles etc)
the user should have the ability to connect these objects using arrows (please see image link)
http://img850.imageshack.us/img850/6999/o33z.jpg
In addition the user should be able to move the objects, and the connecting arrows need to move with the objects so that the arrows keep point to the same objects.
Are there any current web technologies that can to that or is there one that will be a good fit to start using as a basis. I have not done any web work so even javascript might be your answer but please guide me with some specifics.
Look into Jquery UI. There's plenty of abilities in here to do what you specified above. Or you could do it using Flash/ActionScript, although that seems to be (arguably) a diminishing technology.
You can find info on how to use JueryUI here, http://jqueryui.com/draggable/

Why was XPath dropped from jQuery? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I didn't find any documentation as to why XPath support was dropped from jQuery.
Read this: http://ejohn.org/blog/xpath-overnight/
I should, also, probably answer the inevitable question: “Why doesn’t
jQuery have an XPath CSS Selector implementation?” For now, my answer
is: I don’t want two selector implementations – it makes the code base
significantly harder to maintain, increases the number of possible
cross-browser bugs, and drastically increases the filesize of the
resulting download. That being said, I’m strongly evaluating XPath for
some troublesome selectors that could, potentially, provide some big
performance wins to the end user. In the meantime, we’ve focused on
optimizing the actual selectors that most people use (which are poorly
represented in speed tests like SlickSpeed) but we hope to rectify in
the future.

I would like to know of a site that would be useless if JavaScript was disabled [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
I am looking for a site that if I disabled JavaScript the site would be useless, and what other functions would I not be able to use. Does anyone have a name of a site that I can look at? I want to know what no longer works.
You're looking at one right now.
Not quite sure if this is really programming related... but YouTube and Google Docs for instance.
http://jsfiddle.net
Most sites that use javascript heavily become less useful rather than useless. In order to do that, many of them will implement the important parts twice - once with javascript, and a less sophisticated version without.
Despite the popularity of the question, this one doesn't even load w/o JS.
http://www.graphikdesign.it/
Google.com looses it's Instant search capability with Javascript off.

Categories

Resources