- Hard coded in-line Javascript
PROS: Simple. Standard.
Code: Select all
<script type="text/javascript"> var pid = 1; //Page ID </script>
CONS: ? - Via the script source URL
PROS: ?
Code: Select all
<script type="text/javascript" src="/javascripts/nifty.js?pid=1"></script>
CONS: Need to dynamically generate the Javascript. Caching? - Via the URL for HTML
PROS: ?
Code: Select all
http://www.domain.com/rant_about_programming_number_94.html?pid=1
CONS: Passed via GET. Easily messed with by users. Screws up a pretty simple URL scheme. - Via Meta Tags
PROS: Sort of the purpose of Meta tags, indexing. No in-line Javascript just to set a variable.
Code: Select all
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=US-ASCII"> <meta name="keywords" content="programming rant"> <meta name="description" content="Just the rantings of a senile old programmer."> <meta name="author" content="Buddha"> <meta name="published" content="Tue, 14 Nov 2006 16:20:12 +0000"> <meta name="updated" content="Tue, 16 Nov 2006 18:36:18 +0000"> <meta name="pageID" content="1">
CONS: May effect SEO? Never seen Meta tags used this way.
Passing Identifiers to Javascript
Moderator: General Moderators
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Passing Identifiers to Javascript
Been working on a project that handles users comments on HTML pages, a drop-in Javascript. I need to pass a unique identifier for each HTML page to the Javascript. I figure I can pass this ID the following ways ...
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'm not sure. That's why I said "feels". Generally, anything that isn't directly set into the code itself is more flexible in the first place. It would be easy to write a function such as getMetaVar("author") and that's your scalability. All you need to do when you have new parameters is set them in meta tags. I know you could do the same thing by generating the relevant JS but it just doesn't feel as clean. I'm sure it's 100% personal preference though. It's kinda like the discussion of using an array for configuration, or using XML, or using a config object.Burrito wrote:in what way?d11wtq wrote:It just "feels" more scalable.
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
I'll directed them else where to view or post comments if Javascript is disabled.Burrito wrote:I assume having javascript enabled will be a requirement for your users?
Me too. That's why I asked.Burrito wrote:I'm having a hard time convincing myself there is a better alternative to the first option you listed.
Your probably right about that. I just can't think of a good reason not to try it. I doubt it would effect SEO which is my only real concern.d11wtq wrote: I'm sure it's 100% personal preference though.
I'm thinking of using the Meta information for indexing the page so I need to process it anyway. Which is why it occurred to me I could put this one variable in a Meta tag instead of using the in-line Javascript. It's going to be the index.