View Full Version : How's G**gle see java script?
No Life
September 9th, 2005, 08:20 AM
I'm trying to learn some programming to make it easier to make changes on my sites, and I think I am now at the point where I know just enough to make myself dangerous, with a 50/50 chance of getting things right. Anyhoo... here's my question. If I were to create my menu in java script so that whenever a product is added/dropped I don't have to change all the pages, how do the bots read the java script? Do they see nothing, thereby not following links to the other pages?
smokey
September 9th, 2005, 08:52 AM
Make sure you use a <a href="somepage.html">Some Page</a>
dpillz
September 9th, 2005, 09:53 AM
some don't some do .... however if you use php/perl/asp you can include remote files and display them as normal html ///
or you can read a remote file line by line and display it .... (because includes can be dangerous, if someone hack your main source of the includes, all your hosts are gone most likely ..
$menufile = file("http://www.affiliatedemon.com/menus/1000-menu.csv");
for ($i=0; $i<count($menufile); $i++)
{
$line = explode(',',str_replace(""","",$menufile[$i]));
$catg=chop($line[0]);
$produ=chop($line[1]);
}
then you can echo/print the catg and the produ ... this works with comma separated menus in category,product format ...
of course ideally you can cache it on the local disks, and check every hour if it is changed and so on .... but that is the easyest safe way to do this ...
other tips:
you could only read the first line and compare it to the remote (assuming you put a datestamp on it)
in php file() does not allow timeout settings, so if the remote is down your users get a nasty error message (unless you turn error reporting off)
better use socket operations (looks scary, but it is fairly easy)
actually read this whole page:
http://cr.php.net/file
seek to this line " function fetchUrlWithoutHanging($url)"
that will show you a fairly easy socket file read with timeout ...
but beware, fscockopen does not check DNS lookup error, you have to do it yourself
nah .. i am in the writing mood and not in the working one :) maybe i just read forums all day :)
BowFromMI
September 9th, 2005, 10:20 AM
Wow NoLife, if you understood any of that, you are getting smart!
I'm impressed. It's all waaayyyy over my head...
NoLifeToo
DaveM
September 9th, 2005, 10:30 AM
The simple way to approach the JavaScript question is to link to it from you r page rather than including it. For example:
<script language="JavaScript" src="/js/menu.js"></script>
What you have done is created a directory named "js". In that directory you have included your file named "menu.js", which contains your menu JavaScript code. As the Web browser loads the page it will follow the link and include your script.
SE will not penalize you for the tiny bit of code and life will be good!
PillRoller
September 9th, 2005, 11:23 AM
<script language="JavaScript" src="/js/menu.js"></script>
And that way you only need to edit the one file if any products are removed or added.
No Life
September 9th, 2005, 12:09 PM
Bow - didn't have a clue! I did understand PillRoller and Dave though. That was what I was planning to do for eggs-actly those reasons. I'm so sick of having to change every page whenever a new product comes out or one gets dropped.
So each page, I call the function just by adding document.write(menu()). Right? And internal links will still be followed by the almighty search engines?
RxRob
September 9th, 2005, 01:04 PM
dpillz, what do you have against cURL? :)
dpillz
September 9th, 2005, 02:57 PM
dpillz, what do you have against cURL? :)
nothing in particular :)
but opening your own socket just makes sense to me ......
or maybe i just know how to do it, and don't wanna start with a lib i do not really know and do not have a burning need to know :)
actually i am looking at http://cr.php.net/curl and there are some useful examples .. maybe I look into CURL when I have too much time
dpillz
September 9th, 2005, 03:03 PM
nah OKAY I have to admit curl can be easy :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch); if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
I mean I like the simplicity ....
but just to get a file and process it line by line is like using EXCEL to calculate 2+2 .....
or when people encapsulate 3 words of data that can be represented in 3 lines into XML which turns it into tripple the size and give an opportunity for some stupid encoding error ....
Wicked
September 9th, 2005, 03:09 PM
easy my foot!
No Life
September 9th, 2005, 03:24 PM
I'm having a hard enough time with javascript!
chopsticks
September 11th, 2005, 06:54 AM
Well, I've used ALL types of Javascript in my pages... from external calls to objuscated (encoded) script to hide data from the technically inept cut-n-pasters.
It all works... but you can just do a normal server-side include (SSI) too.
I like to put absolute (http://....) URLs in my javascript, not relative (somepage.html) just to be sure the engines can resolve the locations from the javascript.
DaveM
September 11th, 2005, 01:55 PM
I like to put absolute (http://....) URLs in my javascript, not relative (somepage.html) just to be sure the engines can resolve the locations from the javascript.
Yep, good point!
No Life
September 11th, 2005, 02:47 PM
Wrote the javascript, put it on 2 unimportant product pages, and I'll wait and see what the sitemap stats say. If it works, I'm on it!!!
Powered by vBulletin™ Version 4.0.3 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.