NodeGuy/server-date

Make ServerDate independent from server echo

rdoepke opened this issue · 8 comments

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

  • makes it very difficult to minify the code (since you can not simply rely on the JS minification of other JS assets)
  • does not allow to merge the minified JS to a single JS asset file
  • prevents caching of the JS asset itself (as it gets written to the ServerDate.php which cannot be cached neither serverside nor clientside)
  • makes this library more reliant on the server language

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.

I'm open to pull requests. :-)

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?

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

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.

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

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
#23 (comment).

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
#23 (comment).

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