EzDevInfo.com

prerender

Node server that uses phantomjs to render a javascript-rendered page as HTML. To be used in conjunction with prerender middleware.

Chrome Prerender feature gets canceled every time

I'm trying the prerender feature in chrome, but when I check the network, I can see the request is beeing canceled for any link.

chrome developer console

I'm using the following syntax:

<link rel="prerender" rel='nofollow' href="http://example.org/index.html">

I tried the live demo at http://prerender-test.appspot.com/ and got the same result. Why is that?

Update (from https://developers.google.com/chrome/whitepapers/prerender):

In some cases while prerendering a site Chrome may run into a situation that could potentially lead to user-visible behavior that is incorrect. In those cases, the prerender will be silently aborted. Some of these cases include:

  • Note: This is not an exhaustive list. Last updated 11/10/11.

    1. The URL initiates a download
    2. HTMLAudio or Video in the page
    3. POST, PUT, and DELETE XMLHTTPRequests
    4. HTTP Authentication
    5. HTTPS pages
    6. Pages that trigger the malware warning
    7. Popup/window creation
    8. Detection of high resource utilization
    9. Developer Tools is open
    10. Plugins such as Flash will have their initialization deferred until the user actually visits the prerendered page.

But the question is when can I use this feature?


Source: (StackOverflow)

Using prerender with proxy in nginx

I'm trying to use prerender.io to get an snapshot of angularjs pages. Currently I have an NodeJS instance for the web app and nginx reverse proxy redirects requests from port 80 to 4000.

According to prerender nginx manual (https://gist.github.com/thoop/8165802) I can forward search-engine bot requests to the prerender url but because I already have a proxy for NodeJS application, I don't know how can I prerender try_files directive.

My question is, how can I use both NodeJS application proxy and prerender directive?


Source: (StackOverflow)

Advertisements

JSF 2.0. Unable to get POST parameters and cookies in preRenderView event handler

I am trying to develop a service.

The point is that my index.xhtml should get parameters (either POST and GET) and cookies from HTTP Request.

I tried combination with <f:metadata> and <f:event type="preRenderView"> like this:

<f:metadata>  
    <f:event type="preRenderView" listener="#{deConversation.start}"/>  
</f:metadata>

Code for deConversation.start:

public void start(ComponentSystemEvent event) {
    System.out.println("checkLogin");
    HttpServletRequest request = SsoHelper.getRequest();
    String requestSessId = SsoHelper.getRequestSessionId(request);
    String requestRedirect = SsoHelper.getRequestRedirect(request);

    System.out.println("sessId " + requestSessId);

    if (requestRedirect == null || requestRedirect.isEmpty()) {
        requestRedirect = "self";
    }

    if (requestSessId != null) {
        trySessId(requestSessId, requestRedirect);
    }

    externalResourcesHandler.setExternalRedirect(requestRedirect);
    tryToBeginConversation();

    if (!isAuthorized()) {
        SsoHelper.performNavigation("auth");
    }
}

SsoHelper just provides api like this:

public static String getRequestSessionId(HttpServletRequest request) {
    Map<String, Object> cookieMap = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap();
    String requestDeSessionId = null;
    if (cookieMap.containsKey("de_session_id")) {
        requestDeSessionId = ((Cookie) cookieMap.get("de_session_id")).getValue();
    }
    return requestDeSessionId;
}

public static String getRequestRedirect(HttpServletRequest request) {
    return getRequestParam(request, "redirect", "self");
}

public static String getRequestExternalCss(HttpServletRequest request) {
    return getRequestParam(request, "externalcss", null);
}

public static String getRequestParam(HttpServletRequest request, String name, String defaultValue) {
    String[] paramValues = HttpServletRequestHelper.getParamValues(request, name);
    String paramValue = null;
    if (paramValues != null && paramValues.length != 0) {
        paramValue = paramValues[0];
    }
    if(paramValue == null){
        paramValue = defaultValue;
    }
    return paramValue;
}

public static HttpServletRequest getRequest() {
    return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
}

public static void performNavigation(String destination) {
    FacesContext context = FacesContext.getCurrentInstance();
    ConfigurableNavigationHandler handler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
    handler.performNavigation(destination);
}

The point is that I could not get any POST parameters or cookie in method start(). I can get only GET parameters.

Is there any possibilty to read cookies and POST parameters using <f:event type="preRenderView">?


Source: (StackOverflow)

Is there any API to disable prerender feature in chrome?

Without using automation, is there any way to programmatically disable prerender feature (Advanced Setting: Predict network actions to improve page load performance) in google chrome?

I couldn't find any straight forward API that allows me to modify this setting. So, I tried modifying dns_prefetching->enabled in "[Chromedir]\User Data\Default\Preferences" file to "false". But that value was getting reset every time I open Chrome. Using Procmon utility didn't provide me any additional clues on where chrome may store its settings.

Thanks in advance.

Edit: I should mention upfront that using command line option "--prerender" won't work as I need this value to be turned off for all instances of chrome (even when launched by Operating system shell).


Source: (StackOverflow)

how to test prefetch/prerender

I have started to load a few key resources and pages using the prefetch/prerender system.

Is there a way to ensure that the resources in question are actually being preloaded?


Source: (StackOverflow)

"cookie conflict" in Google Chrome Prerender

I have been using Chrome's prerendering functionality using

<link rel="prerender" rel='nofollow' href="/path" />

But after the lates updates, when I try to debug using [chrome://net-internals/#prerender]. It shows that the prerendering was aborted due to "Cookie Conflict".

I tried to debug to make sure if some ajax call is changing the cookies after the page was loaded, but found none. Still the prerender gets aborted. It used to work fine with the previous builds of chrome.


Source: (StackOverflow)

image resize gives slight, brief, pixelation in WebKit browsers

jsfiddle: http://jsfiddle.net/UenFN/. Notice the slight, brief pixelation after the animation. This error only happens in WebKit browsers.

Using jQuery, I have an image resize into a smaller one. The new dimensions are precisely half of the old ones. Right after resizing, however, the image appears slightly pixelated, then about 2 seconds later it looks better.

How can I fix this problem?

EDIT: Still no progress. Any idea is appreciated.


Source: (StackOverflow)

Rel PreRender/PreFetch, does it execute JS?

<!—Firefox Prefetching -->
<link rel="prefetch" rel='nofollow' href="http://www.example.com/page2.html">

<!—Chrome Prefetching -->
<link rel="prerender" rel='nofollow' href="http://www.example.com/page2.html">

If I had Javascript on the page to prerender/prefetch (such as Google Analytics JS), will the prerender/prefetch execute Javascript on the page? Or does it delay any execution of JS until the page is actually requested by the user?


Source: (StackOverflow)

Binding controls on PreRender

I have been led to believe that the best point to bind your controls is the PreRender. As all the controls are ready and this is the last stage before rendering etc. Is this correct or should controls be bound at a different point?

Many Thanks

Louis


Source: (StackOverflow)

Prerender.io not caching pages

I have made an app with AngularJS with an expressJS backend. Now I want to make it crawlable and I've found prerender.io. I think I've done everything correct bur for some reason I don't see any statistics in the prerenderer dashboard.

In my app.configure function I've included the token like follows:

app.use(require('prerender-node').set('prerenderToken', 'my-token'));

And in my HTML I've included the meta-fragment tag:

<meta name="fragment" content="!">

The last ting I've done was to tell AngularJS to use a hashprefix:

$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');

But for some reason, if I refer to the documentation, I don't get the correct result. Below you can see what it is supposed to do:

Google sends a request to your server like this:

http://www.example.com/?_escaped_fragment_=/user/123

You turn the url back into this:

http://www.example.com/#!/user/123

For some reason if I try this it still adds the #! signs add the end of the URL, so if I request the URL of my app like google I get this:

http://www.my-website.com/?_escaped_fragment_=#!/home

So it does not replace the hash in the url. I think this is the cause of my problem.

Thanks in advance!

Edit - if I for example add an extra route then it works:

app.get('/', function (req, res) {
    res.sendfile('./public/index.html'); 
});

app.get('/test', function (req, res) {
    res.sendfile('./public/index.html'); 
});

the '/' route doesn't work the '/test' route does work.


Source: (StackOverflow)

Backbone.js Routing: From hash to hashbang

I have a legacy backbone.js app that I'm currently retrofitting to be properly crawlable by search engines. I've settled on using prerender.io's Node.js + Phantom.js system to serve static HTML renders of my javascript powered site to search engines. One of the requirements for using prerender.io however is that all hash URLs be converted to hashbang (so site.com/#gallery should be site.come/#!gallery). My site currently only uses hash for url routing. How can I switch this to a hashbang?


Source: (StackOverflow)

AngularJS + golang Revel web framework for SEO in Prerender.io

I developed a web site using AngularJS and Revel. But I found the SEO in the single page application is a big problem. I checked the https://prerender.io/getting-started , but I can't found the middleware for Revel installation. Could someone help me how do I contribute that for Revel?


Source: (StackOverflow)

JSF f:event preRenderView in template f:metadata, listener not being called on every page access

Mojarra-2.1.3 as per Glassfish3.1.1 (distributed with Netbeans7.1)

I have a @SessionScoped backing bean Tracker with a listener void reset().

The following works fine in the f:metadata of all XHTML pages that use a template.xhtml, for example /block/view.xhtml, which also takes a query parameter id:

<f:view>
    <f:metadata>
        <f:viewParam name="id" value="#{blockManager.id}"/>
        <f:event type="preRenderView" listener="#{tracker.reset}"/>            
    </f:metadata>
</f:view>

<ui:composition template="/template.xhtml">

As expected, whenever I load (GET) or reload a page, and no matter what the id query parameter, the #{tracker.reset} listener is invoked (as revealed by debug logging).

However, it is tedious to have to include that f:event in every XHTML page (of which I have hundreds), I tried first instead to have it in the f:metadata of my template.xhtml. But when I did something strange happened. It only called #{tracker.reset} once, the first time /block/view.xhtml was loaded (no matter what the id query parameter was), and thereafter it was not called again until I loaded another page with a different viewId, such as /actor/view.xhtml, or /block/list.xhtml, or /index.html.

I examined the viewId using #{facesContext.viewRoot.viewId} in the template.xhtml. It is clear from the point of view of the viewId that the query parameter id plays no role in distinguishing between different block/view.xhtml?id=[id] pages called with different id query parameters, the viewId is always just '/block/view.xhtml'.

During the writing of this stackoverflow posting I discovered the solution to my problem: just place the f:event outside the f:metadata of the template.xhtml (I was using the f:metadata in the template.xhtml for grouping of f:events). This works in template.xhtml:

<f:metadata>
..
</f:metadata>
<f:event type="preRenderView" listener="#{tracker.reset}"/>
<h:head>

But I still have the following question:

Q: Why does it make a difference whether or not I place an f:event inside the f:metadata in a template ?

The reason I ask is that there are lots of examples here on Stackoverflow both of use of an f:metadata in a template.xhtml, and of an f:event inside an f:metadata in a template.

BalusC states at When to use preRenderView versus PostConstruct?:

The preRenderView event is invoked on every HTTP request.

This only seems to be true (to work as expected) if I have the preRenderView f:event in the f:metadata of the final XHTML page, or outside the f:metadata of a template, but not inside the f:metadata of a template.

There seems to be some debate about whether one should have f:event in the f:metadata of a template, or use f:metadata in a template at all.

JSF2 Complete Reference (Burns and Schalk) p.540 states:

The f:metadata tag encapsulates the set of elements used to specify the metadata for a Facelets view, and therefore must be the child of the f:view tag and may not appear in a template. As of JSF2.0, the only purpose of this tag is to encapsulate f:viewParam tags.

But there are lots of examples on Stackoverflow of f:metadata being used inside templates, and there are lots of examples of f:event being used inside f:metadata. It is also discussed here:

JSF: Does it matter whether place f:event inside f:metadata or not

Where BalusC helpfully explained:

.. the <f:event> is not strictly required to be placed inside <f:metadata>. It can be attached to any component. .. It's indeed for pure self-documentary purposes placed inside the <f:metadata> whenever you have a bunch of <f:viewParam>s and would like to hook a <f:event> to invoke an action after all those view parameters have been set. ..

But my experience above indicates that placing and f:event inside an f:metadata of a template gives slightly different (strange) behaviour. Why ?


Source: (StackOverflow)

Issue with session_regenerate_id and Chrome prefetch/render

I have an issue with some session functionality and the way Chrome does prefetching/rendering. I am attempting to interface a piece of forum software (esoTalk) with a custom laravel 4.3 app. I have authentication event listeners that cause laravel to create a php session (in addition the built in laravel session) that allows the forum and app to share authentication details. On access of the forum, and if the user is not logged in - but this shared information exists (i.e. the user has logged in on the laravel app), the forum will log in that user using the information available in the session.

For the most part this works fine except Chromes prefetching appears to be breaking things. If I monitor the forum using a debugger I can see that when I type out the forum url but before I hit enter chrome will access the forum. Following through with the debugger I can see it does everything it needs to do and is successful in logging in. As a final step the forum regenerates the session id to stop hijacking. This is where it breaks. It looks like chrome ignores the new session id (sent via a http SetCookie header) so that when I hit enter I go to the forum (and make a whole new request) using the original session id. This id doesn't exist so I get set up with a new one and consequently lose my logged in status. To the user this just looks like they never got logged in.

I've googled high and low for suggestions as to how I can work around this. I'm loath to removed the session id regeneration as it does serve a security purpose. I also can't disable the chrome prefetching/rendering. All in all I appear to be in a bit of a pickle.

I have created some code that replicates this. Though it relies on the prerendering kicking in (so you'll need to hit each of the files via the address bar a number of times)

// test1.php

<?php

function regenerateToken()
{
    session_regenerate_id(true);
    $_SESSION["token"] = substr(md5(uniqid(rand())), 0, 13);
    $_SESSION["userAgent"] = md5($_SERVER["HTTP_USER_AGENT"]);
}

// Start a session.
session_set_cookie_params(0, '/');
session_name("SessionBork_Test_session");
session_start();

$_SESSION["SentryUserId"] = '99';

regenerateToken();

header('Content-Type: text/plain');
foreach ($_SESSION as $k => $v) {
    echo $k . " = " . $v . "\n";
}

Access test1.php followed by test2.php and you should see a bunch of session variable output. As soon as prerendering/fetching kicks in you'll start getting a broken message.

// test2.php
<?php

function regenerateToken()
{
    session_regenerate_id(true);
    $_SESSION["token"] = substr(md5(uniqid(rand())), 0, 13);
    $_SESSION["userAgent"] = md5($_SERVER["HTTP_USER_AGENT"]);
}

// Start a session.
session_set_cookie_params(0, '/');
session_name("SessionBork_Test_session");
session_start();

if (empty($_SESSION["token"])) regenerateToken();

// Complicate session highjacking - check the current user agent against the one that initiated the session.
if (md5($_SERVER["HTTP_USER_AGENT"]) != $_SESSION["userAgent"])
    session_destroy();

// Log in a the user based on the SentryUserId
// ... logging in, setting userId, regenerating session
$_SESSION["userId"] = '10';
regenerateToken();

header('Content-Type: text/plain');
foreach ($_SESSION as $k => $v) {
    echo $k . " = " . $v . "\n";
}
if ( ! isset($_SESSION['SentryUserId'])) echo "\n--\nPrerendering brokeded me.";

If you can get it hooked up to xdebug in an IDE or something you should see the hidden prerender hit to test2.php (which looks to be absolutely correct in the response) and then the subsequent actual hit when you press enter where it's forgotten who you are.


Source: (StackOverflow)

Does Google Chrome Prerender work with ajax requests [closed]

I'm looking to use pre-rendering to speed up a page, using Chrome prerender:

https://developers.google.com/chrome/whitepapers/prerender

I'm wondering does this work with ajax requests? I have a set of links which load in their pages via a jQuery $.get into a modal. I also have a script which creates the prerender tags for those links.

There doesn't seem to be any performance increase on the ajax load though. Prerendering is working (checked with the troubleshooting section in link above) and it seems to speed up standard links, but not the ajax requests.

It might not work in this way, but I can't find any info about it anywhere else.


Source: (StackOverflow)