Javascript to fetch page title for every webpage, is it good?
-
We have a zend framework that is complex to program if you ask me, and since we have 20k+ pages that we need to get proper titles to and meta descriptions, i need to ask if we use Javascript to handle page titles (basically the previously programming team had NOT set page titles at all) and i need to get proper page titles from a h1 tag within the page.
current course of action which we can easily implement is fetch page title from that h1 tag being used throughout all pages with the help of javascript, But this does makes it difficult for engines to actually read what's the page title? since its being fetched with javascript code that we have put in, though i had doubts, is anyone one of you have simiilar situation before? if yes i need some help!
Update: I tried the JavaScript way and here is what it looks like http://islamicencyclopedia.org/public/index/hadith/id/1/book_id/106 i know the fact that google won't read JavaScript like the way we have done with the website, But i need help on "How we can work around this issue" Knowing we don't have other options.
-
Your welcome. Interesting question. My answer is that if the HTML TITLE is set with client side JavaScript then it's has little change of being picked up as the title by crawlers or Google. Let's say we alter the node element Title value with like this:
In this case it will alter the value after the hard coded HTML title was send to the browser. It would need the crawler to load the document in full and read the HTML title value only after fully rendering it as if it where a human user. This is not likely.
Then we could also try a document write to construct the HTML HEAD tag Title as a string to use for the browser as the title like this:
Will not work as the title text is not actually altered after evaluation of the script line.
This does not work because the title is not set but because it's not actually printed to the browser as a string. The source code for the title still looks like this in to any browser:
As you can see the script does not print the result string of the evaluation to the browser but still sets the value of the document object model node HTML TITLE to the value it evaluates to.
Try it for yourself with this dummy page I made just to be certain.
http://www.googlewiki.nl/test/seojavascripttest2.html And this is the DOM info for this page http://www.googlewiki.nl/seo-checker/testanchor.php?url=http://www.googlewiki.nl/test/seojavascripttest2.html&anchor=testOr am I missing something here?
Hope this helps.
-
Google can read Javascript, but only certain types and implemetations. Is there a way you can set this swap out to happen on the database or server side? That might be the best way to get the live text readable, as most likely the javascript is being rendered and displayed after the initial crawl of the page. Even if it is a milisecond later, Google might not allow/catch it.
-
Any javascript effor is invalid for SEO. Google doesn't read them.
You can try to make it on PHP, it's not complex, search your an replace with meta desc=$var and <title>$var2 (and, also, </head>). Then you can set the meta desc and page title with a variable in your code, and then this effor effectively have SEO value, because when the search engine fetch the page they have title and desc.</p> <p>Maybe this is more work than JS form, but also it's better for SEO and web itself (The JS run takes time on client side).</p></title>
-
Thank you Daniel for the input, Since the code is all messed up and i can't convince the Board to redo the site from scratch. i'll have to go with small tricks with title tags and descriptions to be set, with JavaScript as i just tried, it worked and it now does fetch all the titles and displays them on the browser title, without any significant change in the actual code except for the addition of JavaScript that i just tried.
But i did a test run with Rich snippet testing tool to see what Google pulls in as preview for search results, and it didn't show anything, No title and No description .. alas! So i guess it does mean using JavaScript to fetch title & description won't help? I'm still not sure.
So now the real question i have in mind; Does this Javascript technique that we just used, will it be of any good SEO wise or will have any value?
-
Hi... I would not prefer a client side approach to this. If it's readable depends on the script itself. Although some JS fans will say this alright I would prefer to do this server side with php, or similar, and make a template that does this rewrite. It's not to hard. Or why not a batch run to modify all pages once to hardcode the correct title in the page? Have some scripts that can do this for you if you would like.
Hope this helps.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Why has my home page replaced my sub-category page for set of keywords? Happened 2x in last 2 weeks for day or so only to fix itself. What is going on?
Today I noticed a really weird problem. Our LED Step Lights page (https://www.pegasuslighting.com/led-step-lights.html) has been replaced in the search results with our home page. See screenshot below. As I started to research what was going on, I noticed that this same thing must have happened on January 26 and 27 because in my Analytics I can see that our LED Step Lights sub-cat page had a sudden drop in traffic on those two days only to bounce back again on the 28th. See screenshot below. Our LED Step Lights page has had no changes in content, meta information, or anything in months. We have done no recent link building to this page in years. I don't understand what is going on. This is a popular page for us generating decent traffic. I really don't understand what is going on or even how to try and resolve this problem. I checked our Search Console. No messages. No manual web spam actions. Nothing to suggest that anything is going on except for the weird drops in traffic. Has anyone ever seen this happen before? Does anyone have any ideas as to what may be going on? serp-led-step-lights.png organic-traffic-drops.png search-console-led-step-lights.png
Intermediate & Advanced SEO | | cajohnson0 -
Noindex search pages?
Is it best to noindex search results pages, exclude them using robots.txt, or both?
Intermediate & Advanced SEO | | YairSpolter0 -
301 redirect for page 2, page 3 etc of an article or feed
Hey guys, We're looking to move a blog feed we have to a new static URL page. We are using 301 redirects but I'm unsure of what to regarding page 2, page 3 etc. of the feed. How do I make sure those urls are being redirected as well? For example: Moving FloridaDentist.com/blog/dental-tips/ to a new page url FloridaDentist.com/dental-tips. So, we are using a 301 on that old url to the new one. My questions is what to do with the other pages like FloridaDentist.com/blog/dental-tips/page/3. How do we make sure that page is also 301'd to the new main url?
Intermediate & Advanced SEO | | RickyShockley0 -
Home Page or Internal Page
I have a website that deals with personalized jewelry, and our main keyword is "Name Necklace".
Intermediate & Advanced SEO | | Tiedemann_Anselm
3 mounth ago i added new page: http://www.onecklace.com/name-necklaces/ And from then google index only this page for my main keyword, and not our home page.
Beacuase the page is new, and we didn't have a lot of link to it, our rank is not so well. I'm considering to remove this page (301 to home page), beacause i think that if google index our home page for this keyword it will be better. I'm not sure if this is a good idea, but i know that our home page have a lot of good links and maybe our rank will be higher. Another thing, because google index this internal page for this keyword, it looks like our home page have no main keyword at all. BTW, before i add this page, google index our main page with this keyword. Please advise... U5S8gyS.png j50XHl4.png0 -
Urgent Site Migration Help: 301 redirect from legacy to new if legacy pages are NOT indexed but have links and domain/page authority of 50+?
Sorry for the long title, but that's the whole question. Notes: New site is on same domain but URLs will change because URL structure was horrible Old site has awful SEO. Like real bad. Canonical tags point to dev. subdomain (which is still accessible and has robots.txt, so the end result is old site IS NOT INDEXED by Google) Old site has links and domain/page authority north of 50. I suspect some shady links but there have to be good links as well My guess is that since that are likely incoming links that are legitimate, I should still attempt to use 301s to the versions of the pages on the new site (note: the content on the new site will be different, but in general it'll be about the same thing as the old page, just much improved and more relevant). So yeah, I guess that's it. Even thought the old site's pages are not indexed, if the new site is set up properly, the 301s won't pass along the 'non-indexed' status, correct? Thanks in advance for any quick answers!
Intermediate & Advanced SEO | | JDMcNamara0 -
Duplicate Page Title problems with Product Catalogues (Categories, Subcategories etc.)
Hey guys, I've done a fair bit of Googling and "mozzing" and can't seem to find a definitive solution. In our product catalogue on our site we have multiple ways to access the product for navigation purposes, and SeoMoz is throwing up hundreds of duplicate page title errors which are basically just different ways to get to the same product yet it sees it as a "separate page" and thus duplicating itself. Is this just SeoMoz confusing itself or does Google actually see it this way too? For example, a product might be: www.example.com/region/category/subcategory/ www.example.com/region2/category/subcategory/ www.example.com/region/category/subcategory2/ etc. Is the only solution to have the product ONLY listed in one combination? This kind of kills our ability to have easy refinement for customers browsing the catalogue, i.e: something that falls under the "Gifts for Men" might also be a match for "Father's Day Gifts" or "Gifts for Dad" etc. Any solution or advice is greatly appreciated, cheers 🙂
Intermediate & Advanced SEO | | ExperienceOz0 -
List of Off page techniques
Hello Everyone, Please share the list of off page techniques to improve ranking and which techniques completely avoided?
Intermediate & Advanced SEO | | Alick3000 -
Does title text of homepage effect ranking of sub pages?
Question is pretty much summed up in the title. I realize that title text on a specific page can effect the ranking of that page. But what I'm getting a feeling of lately is that google uses the title text of your homepage to effect the ranking of the site on a whole. Thoughts?
Intermediate & Advanced SEO | | adriandg1