Re: [w3c/webcomponents] Make JavaScript Files a Valid Entry Point to a Web Page (#807)

@Lonniebiz 

> What I wish was possible, is the ability to create a web application without ever leaving my javascript file. I want the ability to write and save a single javascript file, serve it from a web server, and have the web-browser run that file, which then programmaticaly generates the html and css.

> Right now, using javascript, on the client-side, you can programmatically generate all the HTML and CSS on a web page except for the HTML wrapper itself . Right now, the only way to create an HTMLDocument is to feed the web browser server-side-html.

> So, the closest I can come to achieving my goal, is to hand the web browser a meaninglessly empty html file (to satisfy its 1994 expectations) that either encapsulates or links to my single javascript file.

Is this a fair restatement of your goal?:

"""
A developer can deploy a client-side web application without having to write, check in, or maintain an HTML file.
"""

If so, none of that requires changing how browsers treat responses from existing servers.

I'm free to configure my server to generate stub HTML using whatever convention I like.
The below treats paths that end in `.js.html` as requests for a top-level document where the corresponding `.js` file is the start module.

```js
#!/usr/bin/env node

const express = require('express');
const escapeHtml = require('escape-html');
const path = require('path');
const app = express();
const port = 8000;

app.use(express.static(path.join(__dirname, 'static-files')));

// Auto-generate a stub for JS files.
app.get(
  /[.]js[.]html$/,
  (req, res) => {
    const { path } = req;
    const jsPath = path.replace(/[.]html$/, '');

    res.set('content-type', 'text/html; charset=utf-8');
    res.send(`\
        <!doctype html>
        <html>
          <title>Loading</title>
          <body>
            <script type="module" src="${ escapeHtml(jsPath) }"></script>
        </html>`);
  });

app.listen(port, () => console.log(`//localhost:${port}`));
```

Then if I put the JS below in `static-files/index.js` and browse to `localhost:8000/index.js.html` I get a client-side web application.

```js
document.title = 'Look Ma, no HTML!';
document.body.appendChild(document.createTextNode('Hello, World!'));

export default null;
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/807#issuecomment-489649755

Received on Monday, 6 May 2019 14:52:11 UTC