Live data from Hacker News

Show HN: This website is valid JSON

webdatarender.com

101–110 of 240 posts

Re: Show HN: This website is valid JSON

#101
post #86
post #83

RIP SEO

Not really, Google and Bing will read the page correctly with Javascript. Check the page insight: https://developers.google.com/speed/pagespeed/insights/?url=... But it would be even better if they could get the information directly on JSON. So much carbon saved ;)

It's not simply about speed. The page looks like spam.

Re: Show HN: This website is valid JSON

#102
post #10

This is a really cool hack. > The JSON must contain only pure information without any concern about design or markup. Wellll.. I mean the json has markdown syntax in it. That's a lot nicer than html tags for markup, but it's still markup. In case anyone reading hasn't seen it before, browsers have a thing called XSLT built into them that does something similar for XML documents. You serve up your data as XML, add a t…

XSLT is the only way to do HTML templating on the client without using JS. I think that is valuable.

XML+XSLT is vastly, vastly underrated.

Re: Show HN: This website is valid JSON

#103
post #2

Hello everyone, I created a simple script that allows a website to be a valid JSON and still be able to present the information on the browser. Any feedback is appreciated!

It's a fun hack! The website could make it clearer that it only works because browsers tend to be very fault tolerant, and the JSON itself is by no means a valid "web page" (i.e. there are no guarantees it'll render properly).

Re: Show HN: This website is valid JSON

#104
post #99
post #10

This is a really cool hack. > The JSON must contain only pure information without any concern about design or markup. Wellll.. I mean the json has markdown syntax in it. That's a lot nicer than html tags for markup, but it's still markup. In case anyone reading hasn't seen it before, browsers have a thing called XSLT built into them that does something similar for XML documents. You serve up your data as XML, add a t…

> Apparently web standards folks in the early 2000s thought the future was XML all the way down. It should have been, but just like the masses rejected LISP for its parens, the masses rejected XML for the closing tag. We could have avoided PHP and the zoo of MVC frameworks.

We could have avoided the bedlam of javascript hacks if browsers had supported XSLT2.

Re: Show HN: This website is valid JSON

#105
post #44

For those like me who needed a little help... I do not fully understand the browser rendering process (someone who does please chime in), but what I gather about how this is works is: - the content-type of the page is "text/html", so the browser is trying to render html - there is no special meaning of the #render key to the browser (again the browser doesn't know this is json) - browsers are very fault tolerant so t…

In regards to the character encoding issue, I wonder if they could just move the #render to the top of the object by inserting it as the first property.

I'm guessing there might be issues with the streaming nature of html parsers then. If you put it at the top and the JSON is of any non-trivial size you might end up with the script trying to read invalid JSON since it's not fully loaded yet.

Re: Show HN: This website is valid JSON

#106

Earlier quoted context omitted.

I still have nightmares from learning XSLT. It's very cool, but also, very strange, if you come from a procedural language background. Also, XSLT is really given power by being mixed with XPath (which is procedural). I suspect that if I had known more about FP back when I learned it, I would have had an easier time. I wrote up a really long, painful post about XSLT, way back in the early 'oughts.

XSLT is mainly used to transform XML into XML. The resulting document doesn’t have to be XML, though. I remember being assigned a task of parsing and importing a large XML document into a MySQL database. This was supposed to be done on PHP. I kind of felt repulsed by the idea of writing the parser in PHP (it would have been horrible). So, I used XSLT to transform the document into CSV and then just imported it using…

In the beginning of my career, about 15 years ago, I had a job working with a large auto parts retailer and they had all of their products in these massive XML files. We used XSLT to transform those into all kinds of things, including physical printed catalogues that would go in their stores. Obviously the XSLT didn't actually print catalogues, but we did turn them into some format that I forget now (maybe PDF!) that we could just send straight to the printers.

It was pain and suffering developing these style sheets, but once done it worked like a charm.

Re: Show HN: This website is valid JSON

#107
post #99
post #10

This is a really cool hack. > The JSON must contain only pure information without any concern about design or markup. Wellll.. I mean the json has markdown syntax in it. That's a lot nicer than html tags for markup, but it's still markup. In case anyone reading hasn't seen it before, browsers have a thing called XSLT built into them that does something similar for XML documents. You serve up your data as XML, add a t…

> Apparently web standards folks in the early 2000s thought the future was XML all the way down. It should have been, but just like the masses rejected LISP for its parens, the masses rejected XML for the closing tag. We could have avoided PHP and the zoo of MVC frameworks.

I tried programming in XSLT and it was not fun. I'm sure if it took off we'd have the equivalent of Clojure that compiled down to it, but by itself it is not a hacker's language, if you know what I mean.

Re: Show HN: This website is valid JSON

#108
post #44

For those like me who needed a little help... I do not fully understand the browser rendering process (someone who does please chime in), but what I gather about how this is works is: - the content-type of the page is "text/html", so the browser is trying to render html - there is no special meaning of the #render key to the browser (again the browser doesn't know this is json) - browsers are very fault tolerant so t…

In regards to the character encoding issue, I wonder if they could just move the #render to the top of the object by inserting it as the first property.

[deleted]

Re: Show HN: This website is valid JSON

#109
post #44

For those like me who needed a little help... I do not fully understand the browser rendering process (someone who does please chime in), but what I gather about how this is works is: - the content-type of the page is "text/html", so the browser is trying to render html - there is no special meaning of the #render key to the browser (again the browser doesn't know this is json) - browsers are very fault tolerant so t…

You are correct. It's a silly hack. Just because it happens to work doesn't make it a good idea. Turn off JavaScript and you just get JSON text.

I have created a similar silly hack where you can just write markdown directly:

    # Markdown header

    ## Subheader

    ### Section header

    1. Numbered
    1. List

    - Unordered
    - List


    [//]: # (var doc = document.children[0].textContent.split('\n'); md = doc.slice(0, doc.length - 1).join("\n"); document.body.innerHTML = marked(md);
That last line has varying degrees of invisibility in different markdown viewers I looked at. Obviously there's optimization that could be had here but this is equally hacky IMO and simpler since you can just write MD instead of JSON. You lose a couple of key features though -- templated components for example. However, I imagine you could shoehorn those in without much effort.

This has the advantage that without JS enabled you'll get poorly formatted markdown in the browser.

Re: Show HN: This website is valid JSON

#110
post #80
post #73

Earlier quoted context omitted.

Hey! Yes, however now I notice that this is only when running locally. I took your page, replaced script and css with absolute links, and loaded locally as file://

hmm, I didn't find this error locally either. I will try using file://. Thanks for the report. Also, if you are interested, the project is on GitHub: https://github.com/webdatarender

The reason it works locally is because charset detection works different when loading from a local file than when loading from a webserver.

In particular browsers tend to be a lot more enthusiastic about treating local files as unicode than they are for responses from web servers.

The reason the meta charset doesn't pick up is you're missing quotes around `utf-8` (also it may be past the 1024 byte mark, hard to say without running wc).

Post reply on HN