Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Actually using jQuery?
New Posts  All Forums:Forum Nav:

Actually using jQuery? - Page 2

post #11 of 50
Quote:
Originally Posted by Mrzev View Post

It is very unlikely that the jQuery's servers will go down. So, right now its not worth worrying about. If its imperative that the code need 99.9999999% uptime, then it would be a good time to read up on caching.

Doing something like this allows you to take advantage of a CDN but fall back to a local copy on the web server if the CDN is down.
Code:
<script src="http://url.to.cdn/jquery-VERSION.min.js"></script>
<script>window.jQuery || document.write('<script src="path/to/local/jquery-VERSION.min.js"><\/script>')</script>
Quote:
Originally Posted by CynicalUnicorn View Post

Actually making the code work comes first. Optimization comes later.

Optimisation doesn't even need to come later. Unless for academic reasons (which in this case it would be), optimise when performance is not satisfactory, not before. Refactoring for readability is a must, however. It might make sense now but your spaghetti will cause you grief in 2 weeks smile.gif
Edited by randomizer - 3/5/14 at 1:53am
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #12 of 50
Thread Starter 
Quote:
Originally Posted by randomizer View Post

Optimisation doesn't even need to come later. Unless for academic reasons (which in this case it would be), optimise when performance is not satisfactory, not before. Refactoring for readability is a must, however. It might make sense now but your spaghetti will cause you grief in 2 weeks smile.gif

Yeah, but I can't stand inefficiency. It's why the DMV is my least favorite government agency. wink.gif There's a game in alpha right now called Prison Architect. In a certain test map at one point in development, they were rendering 8 frames per second. A few months of one dev tinkering got it up to 12FPS. He turned it over to another guy and it was brought up to 40FPS, using the exact same hardware and rendering the exact same stuff. I doubt that what I'm doing is going to be that resource intensive, but it's a possibility.

Is it possible to assign a variable's name as a number? I'm assuming no since neither variables nor numbers use quotes when called and that would screw up every equation used. Is it possible to fudge it in a function? E.g. a form in an HTML document takes a number as an input and equates it to a variable to output?
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
post #13 of 50
Quote:
Originally Posted by CynicalUnicorn View Post

Yeah, but I can't stand inefficiency.

If you cant stand inefficiency , why learn an advance concept with a smaller net gain over a simple concept with a massive gain? i.e. I saved 2 ms with a better search, but didn't find out about how to do inheritance with the dojo framework until later on.... =(
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #14 of 50
Quote:
Originally Posted by CynicalUnicorn View Post

Yeah, but I can't stand inefficiency. It's why the DMV is my least favorite government agency. wink.gif There's a game in alpha right now called Prison Architect. In a certain test map at one point in development, they were rendering 8 frames per second. A few months of one dev tinkering got it up to 12FPS. He turned it over to another guy and it was brought up to 40FPS, using the exact same hardware and rendering the exact same stuff. I doubt that what I'm doing is going to be that resource intensive, but it's a possibility.

Is it possible to assign a variable's name as a number? I'm assuming no since neither variables nor numbers use quotes when called and that would screw up every equation used. Is it possible to fudge it in a function? E.g. a form in an HTML document takes a number as an input and equates it to a variable to output?

If you can't stand inefficiency, don't use JS.

JS interpreters/compilers are black boxes and knowing what they interpret as optimization is nearly impossible for all but the most basic operations. Even when optimizations are known, care must be exercised. For example, mixing data types in arrays is universally a performance drain though working around this balloons your code and makes load times worse. I would also assume that there would be memory gains from restructuring object order inside an object (due to struct packing in C and due to the fact that compilers can't do this), but there's no way of knowing if this optimization is correct.

If one is worried about efficiency, stay away from jQuery. This can actually be a legitimate performance issue as jQuery is quite large and significantly slower than native calls (but it saves you from all the boilerplate needed to work around the different browser implementations).

Overall, I recommend writing code that works correctly and then profiling and refactoring the slow parts.

One last thing to keep in mind. Code is not compiled immediately. If the code is only run once or twice, the chances are that the browser is going to interpret the code rather than compile it anyway (which means that your most careful optimizations will not do anything for most code).
post #15 of 50
Quote:
Originally Posted by CynicalUnicorn View Post

There's a game in alpha right now called Prison Architect. In a certain test map at one point in development, they were rendering 8 frames per second. A few months of one dev tinkering got it up to 12FPS. He turned it over to another guy and it was brought up to 40FPS, using the exact same hardware and rendering the exact same stuff.

This is optimisation due to unsatisfactory performance, which is what I said you should do wink.gif

Don't get me wrong, I wouldn't go out of my way to write something inefficient. However, I am not going to sit there looking at a loop and wondering how I can make it faster when any improvements will be measured in single digit milliseconds, or the real problem is elsewhere. For example, I am working on a project at the moment which is just a little slow for my liking at one point. The problem is not in the JS though. I have an async HTTP request that is simply taking too long to be processed by the server.
Quote:
Originally Posted by CynicalUnicorn View Post

Is it possible to assign a variable's name as a number? I'm assuming no since neither variables nor numbers use quotes when called and that would screw up every equation used. Is it possible to fudge it in a function? E.g. a form in an HTML document takes a number as an input and equates it to a variable to output?

You'll have to clarify what you mean. I don't think I really follow, but it sort of sounds like you are asking if there is any way to achieve this:
Code:
var 9001;

I don't believe so, since that doesn't conform to Javascript's (or rather Ecmascript's) identifier name requirements.
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E GTX 560 Ti 448 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
post #16 of 50
Also to add on the 8->12>40 FPS thing... dont waste your time optimizing until the end because the stuff you optimize you may end up removing anyways.
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #17 of 50
Thread Starter 
True. As it is I don't think there is much I can do. My question for today is:

Can you convert a string into an argument? Right now, I have a search engine of sorts.
Code:
function displayInfo(atom) {
        $(document).ready(function(){
                $('#name').replaceWith('<li id="name">' + atom[0] + '</li>');
                $('#symbol').replaceWith('<li id="symbol">' + atom[1] + '</li>');
//And so forth...
                $('#boil').replaceWith('<li id="boil">' + atom[15] + '</li>');    
        });
};


$(document).ready(function(){
        $("button[name=search]").click(function(){
                var search = $("input[name=element]").val();
                displayInfo(search);
        });
});

I can call displayInfo(whatever) and display the data found in the arrays. However, .val() converts the text in the text box to a string, and when called in the function it becomes displayInfo("whatever"), which just displays the first 16 characters in that string, one on each line in the unordered list. This is the most straightforward way I can think of to take text entries and output it to a function but it does not work apparently.
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
post #18 of 50
I think you can do it with Eval( ) , but its bad practice.
Code:

var alphabet=new Array(); 

alphabet[0]= "a";   
alphabet[1]= "b";
alphabet[2]= "c";

document.body.innerHTML += eval("alphabet")[2];


-----------------------------------Outputs-------------------------------------
c



I personally would just use a json object for all of the data.

This is a simple example i found online that shows a json search.
http://jsfiddle.net/ifaour/S4YYk/1/

So, when you get the string from the textbox , then you search your data array for the item with that name. As for efficiency, i have no clue... you may be better off creating a list of names and using that as an index for another list, i really dont know.
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #19 of 50
RANDOM KNOWLEDGE TIME!!!!

I looked up how to spell Alphabet just in case i spelled it wrong, then i was thinking aww it woulda been better as Alphabit . So, I decided to lookup the latin origin of the word. Its basically Alpha + Beta , the first 2 words of the Greek alphabet. Then that makes me wonder.... why do we not have words for our letters? I know in the military they use THIS , but that's not an offical word association for the english language. (I almost used the word Dictionary in the programmatic sense instead of association =P)

But then again... why do greek letters have a word association? I cant think of any other language were they create new words, just for their letters.
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #20 of 50
Thread Starter 
Changing
Code:
displayInfo(search);

to
Code:
displayInfo(eval(search));

works perfectly. I'll link a zip folder or something, or possibly just copy and paste the text when I finish this and tell you what is JS, CSS, and HTML, when I finish.
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
Triumvirate
(20 items)
 
Osmium
(8 items)
 
For Sale: [FS] Z97 system: Xeon and RAM
$160 (USD) or best offer
CPUMotherboardGraphicsGraphics
i7-5775C ASUS Sabertooth Z97 Mark 2 Sapphire RX 480 (reference) MSI Low-Profile 750Ti 
RAMHard DriveHard DriveHard Drive
Corsair Dominator Platinum - 2x8GB Crucial M500 - 960GB Samsung 840 - 250GB WD Scorpio Blue - 1TB 
Hard DriveCoolingCoolingOS
ADATA SP900 - 64GB Scythe BIG Shuriken 2 Rev. B PNY Quadro 600 blower Windows 10 
MonitorMonitorMonitorKeyboard
ASUS VE247H - 1080p Gateway FPD1960 - 1280x1024 Samsung S20D300 - 900p, portrait Rosewill RK9000I - Cherry MX Blue 
PowerCaseMouseOther
Rosewill HIVE 650W Riotoro CR1080 SteelSeries Rival 100 CyberPower 1500PFCLCD 
CPUMotherboardRAMHard Drive
AMD A10-7870K ASRock FM2A88X-ITX+ G.Skill Ripjaws X - 2x4GB @ 2400MT/s Samsung 840 120GB 
CoolingOSPowerCase
Evercool EC-HPS-810CP Windows 7 Pro 64-bit PicoPSU-120-WI-25 Mini-Box M350 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Actually using jQuery?