NodeGuy / server-date

Make the server's clock available in the browser.
http://www.nodeguy.com/serverdate/
Mozilla Public License 2.0
193 stars 52 forks source link

Make ServerDate independent from server echo #23

Closed rdoepke closed 8 years ago

rdoepke commented 9 years ago

Currently, the Javascript needs to "finished" in the backend language via echo and the current timestamp and thereby called. This is bad, since it

Instead, the ServerDate.js could be independently embeddable to the applications JS assets and then, by triggering AJAX requests or the previous ServerDate(now) call written in an embedded script file, start the initialization prozess.

NodeGuy commented 9 years ago

I'm open to pull requests. :-)

broomstick73 commented 9 years ago

I've never used Github before but I'd like to learn so please excuse my ignorance. To make that change is a 3 line change in ServerDate.js so I'd like to submit a pull request to "fix" ServerDate so that it works as described with as few changes as possible.

My suggestion would be to pass in the client-side current date to the function for the initial datetime and then get updates from the server by requesting a copy of the javascript file and reading the date time out of the server response header ("Date"). This removes any dependence on server-side rendering and makes it backend-agnostic so it will work with PHP, Node, IIS.

However; this would mean modifying the PHP & NodeJS example html pages so that they directly reference ServerDate.js and not ServerDate.PHP, etc and remove the server-side rendering of "($now)" - should I make that part of the Pull request? or just send you ServerDate.js and let you decide what you want to do with it?

NodeGuy commented 9 years ago

Is the server response header ("Date") precise enough to be worth reading?

broomstick73 commented 9 years ago

Http response header "Date" seems to come back with time accurate to the second in my limited testing.

If this is accurate enough or not probably depends upon the usage of the time on the client. For my purpose time accurate to the second was adequate - I was displaying a timer in seconds based on server side events.

You raise a good point though.


James C (Sent from my iPhone)

On Sep 22, 2015, at 5:10 PM, David Braun notifications@github.com wrote:

Is the server response header ("Date") precise enough to be worth reading?

— Reply to this email directly or view it on GitHub.

NodeGuy commented 9 years ago

OK, I like all of your suggestions. Please submit a pull request (including the changes to the examples) and I'll review it.

broomstick73 commented 9 years ago

Does this work in IE? I don't have a PHP environment to have tested the original so I wonder if I broke it. It works fine in Chrome but not in IE.

Any ideas?


James C. james.conley@gmail.com

On Thu, Sep 24, 2015 at 1:40 PM, David Braun notifications@github.com wrote:

OK, I like all of your suggestions. Please submit a pull request (including the changes to the examples) and I'll review it.

— Reply to this email directly or view it on GitHub https://github.com/NodeGuy/ServerDate/issues/23#issuecomment-142999994.

broomstick73 commented 9 years ago

Seems to work in Chrome, Firefox, and Safari but breaks in IE. I think IE's "Intranet compatibility mode" is making it break on the console.log() statement.


James C. james.conley@gmail.com

On Fri, Sep 25, 2015 at 9:32 AM, James Conley james.conley@gmail.com wrote:

Does this work in IE? I don't have a PHP environment to have tested the original so I wonder if I broke it. It works fine in Chrome but not in IE.

Any ideas?


James C. james.conley@gmail.com

On Thu, Sep 24, 2015 at 1:40 PM, David Braun notifications@github.com wrote:

OK, I like all of your suggestions. Please submit a pull request (including the changes to the examples) and I'll review it.

— Reply to this email directly or view it on GitHub https://github.com/NodeGuy/ServerDate/issues/23#issuecomment-142999994.

NodeGuy commented 8 years ago

I don't have IE to test with and don't know.