Git Product home page Git Product logo

Comments (17)

Munter avatar Munter commented on September 26, 2024

The API is unchanged and all units tests are running without any errors. This must be a use case we haven't seen before.

Couldn't find base asset for [HtmlImage/98: [Html/2 file:///root/bytesamurai/web/public/templates/landing.html] => /img/preview/tab-slide1.png]

And you are sending in landing.html as an initial asset.

So this means Assetgraph is looking for file:///root/bytesamurai/web/public/img/preview/tab-slide1.png
Does this file exist?

I suggest switching back to 1.4.0 to get you back up working again. Could you also give us an output of tree in your web root and the content of landing.html so we can try to recreate this problem in a test case?

Off topic: You are giving builder several html-files, many of which are templates. If these are all the html-files in your application you can target them with **/*.html, which is also the default fallback pattern if you simply don't define any source files at all.

from assetgraph-builder.

papandreou avatar papandreou commented on September 26, 2024

Yes, this is simply a regression, sorry about that. It happens when you have an unreferenced HTML fragment with outgoing relations in your project -- that is a file with an .html extension, but no <!DOCTYPE>, <head>, or <body>.

It's fixed it in 1.4.3 -- buildProduction no longer throws an error, but assets referenced by the HTML fragment aren't added to the build either. The reason is that relative urls found in those HTML fragments need to be resolved from the url of the including HTML asset.

The right way to fix this would be for you to reference the HTML fragment using a GETSTATICURL relation from a script in your main HTML file, such as:

<script id="bootstrapper">
    window.GETSTATICURL = function (url) { // , placeHolderValue1, placeHolderValue2, ...
        var placeHolderValues = Array.prototype.slice.call(arguments, 1);
        return url.replace(/\*\*?/g, function ($0) {
            return placeHolderValues.shift();
        });
    };
</script>
<script>
    function getTemplateUrl(name) {
        return GETSTATICURL("web/public/templates/*.html", name);
    }
</script>

... essentially what was suggested on https://github.com/One-com/assetgraph-builder/issues/41

The presence of that GETSTATICURL relation will cause all your templates to be added to the build and tell buildProduction that relative urls found in the templates are to be resolved from your main HTML.

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

Several things I'd like to comment on:

@Munter

If these are all the html-files in your application you can target them with **/*.html
The glob pattern **/*.html is unusable for me because several of my HTML fragments contain underscore template declarations, and are dynamically generated, and we don't have a solution for that. So instead I specifically reference the 'plain html' fragments in my build command

Assetgraph is looking forfile:///root/bytesamurai/web/public/img/preview/tab-slide1.pngDoes this file exist?
Yep, it exists. The img reference is properly handled in 1.4.0

@papandreou
It's fixed it in 1.4.3 -- buildProduction no longer throws an error, but assets referenced by the HTML fragment aren't added to the build either.

Whoa, I need clarification here; are you saying that starting from 1.4.3, all of the templates I add to the command line in my buildproduction step wont have the references rewritten? This is a critical point.

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

It may be that I misunderstand the last comment, but it sounds like we are saying that in 1.4.3, specifying template fragments in the buildProduction command will no longer handle those references and the assets won't be in my resulting build.

If this is what is being proposed, this is unworkable. You are making a breaking change to your libraries public API. And you are doing it in a patch release. I cannot stress how important it is to follow semantic versioning when you release a product that has an API.

I really don't want to sound crabby or anything; I genuinely love this tool, and it's saved me tons of time, and my websites that rely on it run like a dang cheetah. I can deal with lacking documentation, a hard to understand GETSTATICURL implementation, and no viable workaround for my templated html fragments, but if you can't follow semver and keep your API stable I can't use this product for my production sites.

from assetgraph-builder.

papandreou avatar papandreou commented on September 26, 2024

I apologize. I didn't do it because of semver ignorance, I just didn't think of it as a breaking change, because I didn't anticipate that someone would use buildProduction like this. I still don't think you're doing it right, but I'll adjust my threshold for when to bump the minor version instead of the patch version in the future.

Whoa, I need clarification here; are you saying that starting from 1.4.3, all of the templates I add to the command line in my buildproduction step wont have the references rewritten? This is a critical point.

If your templates/HTML fragments have incoming relations that can be "traced" back to a non-fragment HTML asset, they will get their references rewritten. It doesn't matter whether they were mentioned explicitly on the command line or if they were discovered through that incoming relation.

Here's an example where just mentioning index.html on the buildProduction command line will automatically add templates/myTemplate.html and images/image.png to the project and rewrite the references correctly:

index.html:

<script>
    $.ajax(GETSTATICURL("templates/myTemplate.html"), ...);
</script>

templates/myTemplate.html:

<h1>This is a template with an image: <img src="images/image.png"></h1>

This also illustrates the problem that caused me to make the change in the first place: Because templates/myTemplate.html is an HTML fragment/template that will be injected into index.html at runtime, its relative references such as image.png should be interpreted as relative to index.html, not templates/myTemplate.html.

The browser won't know which url the text <h1>This is a...</h1> originally came from. If templates/myTemplate.html doesn't have any incoming relations, it doesn't make sense to resolve relative references from it, and that's why they're left alone as of 1.4.3. I hope that makes sense?

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

I still don't think you're doing it right

I think you're missing the point. Look at the first reply from @Munter: https://github.com/One-com/assetgraph-builder/issues/41

If you instead do buildProduction [options] http-pub/index.html http-pub/tpl/application.html then assetgraph will have both index.html and application.html as initial assets and populate the graph for them.

The point is I was relying on this feature which you guys recommended in 1.4.0. Then it broke, in 1.4.1+ I get that you guys aren't recommending doing this anymore, but the point is I was relying on that capability and it suddenly broke, despite the patch number incrementing, which led me to believe it would be a change that didn't touch the API.

Anyway, I'll try the 1.5.5 version. I have never been able to get the GETSTATICURL function working. It just doesnt seem to rewrite the template files or pick up the relations. Is there a changelog for the releases? I can't find it in the repo.

from assetgraph-builder.

papandreou avatar papandreou commented on September 26, 2024

I still don't think you're doing it right

I think you're missing the point. Look at the first reply from @Munter: #41

Did you miss the part where I apologized above?

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

@papandreou I didn't genuinely didn't mean to suggest anything or lay any blame in the last comment. :( If it came off that way I apologize. I'd like to move forward. Is there a changelog for the stuff that got introduced from 1.4.2 -> 1.5.5? I'd like to get a rough sense of what has changed. Also I'm assuming that GETSTATICURL is now the only strategy for pulling in dynamic content, is that right?

from assetgraph-builder.

papandreou avatar papandreou commented on September 26, 2024

I didn't genuinely didn't mean to suggest anything or lay any blame in the last comment

I didn't mean to overreact either :)

Is there a changelog for the stuff that got introduced from 1.4.2 -> 1.5.5? I'd like to get a rough sense of what has changed.

Only the git log: One-com/assetgraph-builder@v1.4.2...v1.5.5

I try to write thorough commit messages, although I realize it would be nicer with a real changelog -- or even a blog post when something major happens. The project as a whole needs to get to grow better communication skills. I haven't really figured out how to approach the documentation effort, and there're still some things I haven't cracked yet, such as how to make GETSTATICURL and related things more easily available (perhaps as a separate library).

Also I'm assuming that GETSTATICURL is now the only strategy for pulling in dynamic content, is that right?

If by "dynamic content" you mean external files with templates, static JSON, and HTML fragments (or images, whatever you need to fetch by URL from JavaScript), then yes. You can also use GETTEXT if you need the file contents rather than a url. It's another undocumented helper function that's modelled as a relation:

var contentsOfExternalFile = GETTEXT('loremipsum.html');

buildProduction will compile this to (before minification of the JavaScript):

var contentsOfExternalFile = "<p>Lorem ipsum dolor...</p>"

GETTEXT doesn't support wildcards like GETSTATICURL, but come to think of it I don't see why it couldn't :)

Put this function into your <script id="bootstrapper"> as with GETSTATICURL and it'll also work in development mode (with a synchronous XHR): https://github.com/One-com/assetgraph-builder/blob/v1.5.5/lib/bootstrapper.js#L175-L195

from assetgraph-builder.

papandreou avatar papandreou commented on September 26, 2024

Anyway, I'll try the 1.5.5 version. I have never been able to get the GETSTATICURL function working. It just doesnt seem to rewrite the template files or pick up the relations. Is there a changelog for the releases? I can't find it in the repo.

If you can think of a way to make your frontend code available to me, I'll take a look. I promise I won't rip it off :)

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

@papandreou haha I'm not worried about you ripping it off. It's not worth stealing. :) I haven't responded in a while because I've been working on converting the code to require.js. It seems to work now so I'm ready to get more ambitious and try re-adding the latest version of assetgraph-builder to the build chain.

Question: is assetgraph-builder meant to work with r.js, or is it a drop-in replacement?

from assetgraph-builder.

Munter avatar Munter commented on September 26, 2024

Assetgraph-builder should work as an r.js replacement.

I haven't heard any feedback from anyone using the entire collection of require.config properties, so I'm not certain that all of them are covered in the same way as r.js would. If you run into trouble we'd love to hear it. Full feature compatibility is a goal.

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

cool, I'll check it out. :) I don't use many properties in my require.config. The only thing that seems like it might be a problem at the moment is that one of my modules references a url. Like this:

define [ 'jquery', '//'+window.location.host+'/user' ], ( $, rawuser) ->
...

Will assetgraph-builder recognize that the 2nd argument in my define is a fully qualified URL and not mess with it?

from assetgraph-builder.

Munter avatar Munter commented on September 26, 2024

Afair it will not touch strings it cannot understand. If I am wrong you might need to wrap this in GETSTATICURL('//'+window.location.host+'/user')

But I'm not sure I understand why you need such complexity. Isn't '//'+window.location.host+'/user' equal to /user ?

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

Isn't '//'+window.location.host+'/user' equal to /user ?

It is equal, but the problem is that the contents of /user is dynamic and needs to be served at application load time. If I specify it as /user, r.js will inline it at compile time.

from assetgraph-builder.

Munter avatar Munter commented on September 26, 2024

Assetgraph won't. But it might throw an error about a missing file.
However I'm pretty sure your concatenated string will work. I'm currently doing delayed loading of analytics scripts using requirejs for script loading. When assetgraph sees a url as a requirement it will keep it as is and warn you in the console at build time

from assetgraph-builder.

mreinstein avatar mreinstein commented on September 26, 2024

I'm going to close this issue because it's all over the place and far off the original topic. I should have opened separate issues for several of these items.

from assetgraph-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.