Skip to content

Commit

Permalink
Adding loading attr to iframe and creating wasm/README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
John Doak authored and John Doak committed Mar 29, 2021
1 parent 5bddfa8 commit c1e2cec
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
12 changes: 12 additions & 0 deletions html/iframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ const (
AllowTopNavigation Sandbox = "allow-top-navigation"
)

// IFrameLoad indicates when to load an IFrame's content.
type IFrameLoad string

const(
// EagerILoad loads the IFrame even if it isn't visible yet on the screen. This is the default.
EagerILoad IFrameLoad = "eager"
// LazyILoad loads the IFrame only when it becomes visible on the screen.
LazyILoad IFrameLoad = "lazy"
)

// IFrame represents a division tag.
type IFrame struct {
GlobalAttrs
Expand All @@ -68,6 +78,8 @@ type IFrame struct {
ReferrerPolicy ReferrerPolicy
// Sandboxing enables an extra set of restrictions for the content in an <iframe>.
Sandboxing Sandboxing
// Loading indicates the way the browser loads the iframe (immediately or when on the visible screen).
Loading IFrameLoad

Events *Events
}
Expand Down
3 changes: 2 additions & 1 deletion html/iframe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func TestIFrame(t *testing.T) {
Width: 110,
ReferrerPolicy: OriginWhenCrossOrigin,
Sandboxing: Sandboxing{AllowFormsSB, AllowPopupsSB},
Loading: LazyILoad,
},

want: strings.TrimSpace(`
<iframe name="name" src="https://vimeo.com" allow="autoplay; fullscreen" allowfullscreen="true" ` +
`allowpaymentrequest="true" height="110" width="110" referrerpolicy="origin-when-cross-origin" ` +
`sandbox="allow-forms allow-popups" accesskey="key" onerror="handleError"></iframe>
`sandbox="allow-forms allow-popups" loading="lazy" accesskey="key" onerror="handleError"></iframe>
`),
},
}
Expand Down
49 changes: 49 additions & 0 deletions wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
NOTE: This is a work in progress and neither the doc nor the package is ready for rock and roll.

WebGear WASM provides packages to simplify using WASM in Go utilizing by boostrapping all files needed for WASM, utilizing the Webear html package and providing UI DOM manipulation without having to get into syscall/JS.

## Why Use This?

- You dislike Javascript
- You like the other WebGear packages
- You don't want to figure out how to bootstap WASM

## Production Ready?

Nope.

Look, WASM is still somewhat experimental in Go. WASM itself is
designed for C++ and doesn't have GC hooks. So binaries are bigger
than they should be. Yeah, there is tinyGo, but that starts getting
way harder.

Here's the thing: is your app a large codebase that is revenue generating at scale? If so, go back to JS.

If not (99% of everyone out there), you can try something different.

## Concepts

### How WASM bootstrapping works

Conceptually, WASM is like Javascript. With JS you push code from the server to the browswer and the browser runs the code.

The big differences are that with WASM, you push Javascript and HTML to the browser that then fetches your WASM from the server and then runs it.

The Javascript for bootstrapping is provided by the Go team. But you have to serve it and setup the WASM download.

Luckily for you we automate that whole thing so you don't have to worry
about it.

### WASM code is compiled for a different environment

When you write your WASM code, you will be compiling for a new target. You can't run tests like normal because you can't run WASM in your environment. Basically any package that uses syscall/js cannot be tested in your normal environment.

### When you want to see changes, you have to recompile the WASM and re-run your server

You can't just "go run main.go". Your server is serving a WASM file,
that WASM file is its own compiled binary.

As you will see below, this just means there are two compilations that
must happen.


2 changes: 1 addition & 1 deletion wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bootstrapping JS code.
This package along with the webgear/html and webgear/component remove the need to use HTML or JS within
your application.
The app handles all the client display while and should fetch content from the server in which to display.
The app handles all the client display and should fetch content from the server in which to display.
This should be done via REST or other HTTP based calls.
*/
package wasm
Expand Down

0 comments on commit c1e2cec

Please sign in to comment.