ssdom
v1.5.1
Published
Server Side DOM
Downloads
4
Readme
ssdom - Server Side DOM
This is a standalone application to create a server side dom. I made it to replace my old server side dom sdom.
ssdom heavily uses jsdom to run the server side dom. If there are any dom features not present I'd recommend forking jsdom and implementing it there.
The goal of ssdom is to be light weight and simple. I plan to improve jsdom instead of ssdom.
How to use ssdom
Single site command line:
ssdom /my-website/main.html --port 80
Mutli site command line:
Use {HOSTNAME}
in the path argument to insert the hostname to the html path.
ssdom /sites/{HOSTNAME}/main.html --port 80
Programatically
Provide html path string.
var ssdom = require("ssdom");
var server = ssdom("/my-website/main.html");
server.listen(80);
ssdom will then run on your script tags with the attribute context
. Valid values for the context attribute are server
or server-only
. The attribute is completely optional. However if the context attribute is omitted the script will not run on the server.
...
<body>
<script context="server">
// this script will run on both the client and server.
</script>
<script context="server-only">
// this script will only run on the server.
</script>
<script>
// this script will only run on the client.
</script>
</body>
...
If a server
or server-only
script affects the document's source in anyway it will show up on the client's browser. For example if a server-only
script appends a <div>
to the body it will be present on the client's browser.
This allows you to handle sensitive data on the server while using the dom or just remove or add content depending on whos viewing it.
Folder Hierarchy
Currently ssdom uses a fixed folder hierarchy where things can be placed. Eventually these should be customizable in one way or another.
/my-website
/public
- Files that get served statically to the client and are sometimes loaded on the server as well.
/private
/content
- HTML files which can be retrieved with loadContent() as element objects.
/data
- JSON files which can be retrieved with loadData() as js objects.
/scripts
- Scripts with context server or server-only are placed in here.
FAQ
(These aren't actually frequently asked questions. I just made them up.)
Q: Custom attributes are supposed to be prefixed with data-
. Using an attribute like context
is ilegal!
A: Valid context
attributes get removed before being sent to clients, so this should be a non-issue.