Open ebidel opened 9 years ago
I tried the rather obvious technique of using the appengine-web.xml file for defining this but it does not allow "<" in the value of the http-header tag.
`
</include>`
I managed to add the Link
header by excluding my index.html from the list of static files:
<public-root>/static</public-root>
<static-files>
<include path="/static/**" />
<exclude path="/static/index.html" />
</static-files>
And using a Filter to intercept requests, populate the header and finally forward to index.html. Something like this:
public class IndexDispatcherFilter implements Filter {
private final static String preloadResources = Joiner.on(",").join(ImmutableList.<String>of(
"</fonts/roboto/Roboto-Regular.ttf>; rel=preload; as=font",
"</styles/app-main.css>; rel=preload; as=style",
"</scripts/app.js>; rel=preload; as=script",
"</elements/app-main.html>; rel=preload; type=document"
));
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
String scheme = request.getScheme();
String nopush = request.getParameter("nopush");
if (null == nopush && "https".equals(scheme)) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.addHeader("Link", preloadResources);
}
RequestDispatcher rd = request.getRequestDispatcher("/index.html");
rd.forward(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO: dinamically load content to push from json file
}
@Override
public void destroy() { }
}
Ideally this filter would get the assets to push from a json file (like the python drop in does).
The appengine-web.xml file also has a length limit for the value attribute which makes it a poor choice as well. I'll try your idea.
I implemented a filter and it still does not really work. Unless my header value is arbitrarily short, which is impractical sense we need to include the giant domain name for every file, the header just gets dropped. Anyone know if there is a way to configure max header value length in app engine?
I don't know about a "max header value length", but GAE limits the number pushed assets to 10 (I think). Even if you manage to add 50 only the first 10 would be pushed.
BTW, if someone wants to add a Java demo to the examples folder that would be welcomed :)
On Thu, Jun 16, 2016, 9:09 AM Joshua Oster-Morris notifications@github.com wrote:
I implemented a filter and it still does not really work. Unless my header value is arbitrarily short, which is impractical sense we need to include the giant domain name for every file, the header just gets dropped. Anyone know if there is a way to configure max header value length in app engine?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GoogleChrome/http2push-gae/issues/8#issuecomment-226533851, or mute the thread https://github.com/notifications/unsubscribe/AAOigCwu-QbGvvn8mro4CTjXTr-dOd0Jks5qMXU7gaJpZM4GOB5Y .
I managed to add all 12KB of file names (by appending multiple link headers), sadly it was still ineffective because it looks like it ignores nearly all the push requests anyway (your 10 number looks about right even though I have not confirmed it). I am now officially confused as to the purpose of this. The I/O talks made it sound like vulcanizing is now an anti-pattern because of http/2 push. If I can only push 10 files, then it is next to useless for a webcomponents project that uses tons of little files by design. Am I misunderstanding something?
@craftyc0der 10 is the limit imposed by GAE right now. That doesn't mean other h2 servers impose the same restriction.
I'm not sure it's advisable to ever push dozens of resources. There's the potential to needlessly eat up bandwidth and actually bottleneck your initial page. What was showed at I/O with the PRPL pattern is pushing a few critical resources (push), render those resources for a fast paint, preload load additional resources for routes, then lazy load them on demand. To set that up, it requires care in how you construct you architect you app. The Polymer CLI can help if you're using Polymer.
Just the neon-animation tag is 9 files. Is there a legit way to build a modularized webcomponent page that could actually render with 10 files? I'm trying to understand why we were told that vulcanization is an antipattern if we still basically need to serve files one at a time. Should I just come back to this in 6 months? Am I too early?
That's something the Polymer team needs to figure out. For example, the https://shop.polymer-project.org/ demo uses very few (any?) of the current element set. I think one thing we'll need to explore is elements that don't have 1000s dependencies if the PRPL pattern is going to work well. My suggestion is to bring this up on the Polymer issue tracker. This project is unrelated to polymer :)
We've gone way off-course from the original issue. Let's keep it focused on a Java example for push on GAE.
Sorry to take us off course. Thanks for taking the time.
I would be very grateful if you could point to any Java documentation on this topic. I've been Googling for a couple days on this topic and have not found anything on how to describe what to push or how to actually do the pushing. The server must need to know what to push, as they do not read minds. Furthermore, if the server is serving index.html when does it even get a chance to execute some code? I am assuming that this only works via servlet but without any documentation I'm mostly just confused. Thanks for any pointers.