timvdalen 6 years ago

Repo: https://github.com/saiscode/safe-harbor

Do you have an explanation of the source[1] somewhere? I don't really understand why you'd need window.performance or why this requires PubNub (Which also doesn't seem to be loaded as a dependency).

[1]: https://github.com/saiscode/safe-harbor/blob/master/assets/j...

  • saimiam 6 years ago

    I had a couple of constraints which made me go with a tool like Pubnub.

    1. I wanted to release this to the public.

    2. I wanted to have the option of adding support for future socialmedia referrers without releasing new code.

    To solve for 2, I chose to create a central server which pushes out up-to-date styling instructions on request. The alternative would have been to create a static css file which runs into issues of caching.

    To solve for 1, I chose messaging (PubNub) instead of http to (a) avoid dealing with CORS because I wasn't sure I'd get it right because my infra is selfhosted (b) learn and use messaging in a live app.

    > window.performance

    That flag is to check if a page is being reloaded or not. Since the referrer http header (from where javascript presumably gets its value) persists across reloads, to keep track of true referrals vs reloads, I check for the value of this flag.

  • dylz 6 years ago

    window.performance.navigation.type = 1 is a reload, = 0 is a navigate. It is checking if the page loaded via clicking a link or otherwise, at least.