Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using layouts introduces a lot of repetition in browser files #3

Open
jsumners opened this issue Oct 11, 2016 · 4 comments
Open

Using layouts introduces a lot of repetition in browser files #3

jsumners opened this issue Oct 11, 2016 · 4 comments
Assignees

Comments

@jsumners
Copy link

Senario:

You have a layout named default and two pages, A and B, that each use the layout. Pages A and B have resources that are common between them, so default has a browser.json. For example:

{
  "dependencies": [
    "./foo.css",
    "./bar.js"
  ]
}

Further, page A does not depend on any extra resources but page B does. Thus, page B has a browser.json:

{
  "dependencies": [ "./baz.js" ]
}

Now, if the layout were:

<lasso-page package-path="./browser.json" />
<html>
<head>
  <lasso-head />
</head>
<body>
  <layout-placeholder name="content" />
  <lasso-body />
</body>
</html>

And the template for B is:

<lasso-page package-path="./browser.json" />
<layout-use('../../layouts/default/template.marko')>
  <layout-put into="content">
    <form>some form that gets validated by `baz.js`</form>
  </layout-put>
</layout-use>

Then when we render the page baz.js will not be referenced; only the lasso-page in the default layout gets processed.

So, in order to "fix" this, we have to remove the lasso-page from the layout template and add one to each of the templates for A and B. Then each page A and B will need to include a dependency of "../../layouts/default/browser.json". Whereas before, A didn't even need a browser.json and B's only listed the additional dependency.

This is quite cumbersome. I'd like to see lasso-marko create a union of all the dependencies listed in all referenced browser.json files. I also think the inner-most dependencies should be inserted last. In this case it would be, for page B:

<script src="foo.css">
<script src="bar.js">
<script src="baz.js">
@patrick-steele-idem
Copy link
Contributor

Thank you for writing up your thoughts @jsumners. @mlrawlings is working on an enhancement to support static code analysis of marko templates to discover which dependencies need to be sent down to the browser. That is, we are making enhancements to allow <lasso-page/> to be invoked with no attributes and it will automatically inspect the page template and all of its dependencies to determine which dependencies need to be sent down from the browser. In addition, if you are using the lasso CLI then the lasso CLI will now support a --page argument:

lasso --page src/pages/home

I think these changes will address any concerns around repetition since it will all be driven off of static code analysis (even for the top-level page).

We'll update here with updates. If you have any other ideas or thoughts, please share. Thanks again.

@gilbert
Copy link

gilbert commented Dec 13, 2016

Any updates on this? I'm very interested in seeing this change :)

@patrick-steele-idem
Copy link
Contributor

@mlrawlings has made good progress on this enhancement and demoed it internally this past week with marko v4. Michael, do you want to add any more comments?

@jsumners
Copy link
Author

(ping)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants