jeroennoten / Laravel-Prerender

Laravel middleware for prerendering javascript-rendered pages on the fly for SEO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implementation

tenzopro opened this issue · comments

commented

For some reason I seem not to get how to implement this. I have Angularjs on frontend and Laravel 5 on backend. Pretty much done all the set up in the ".env" file. i've added the tag '' in "layout.blade.php" which is a master page. But where do i get the prerender library/file and where should it go etc. I think i'm missing something.

Have you added the service provider to config/app.php too?

commented

yes. like so: config/app.php

'Nutsweb\LaravelPrerender\LaravelPrerenderServiceProvider',

my .env looks like this:

PRERENDER_TOKEN=my_prerender_token
PRERENDER_URL=my_domain
PRERENDER_ENABLE=true

masterpage: layout.blade.php

"html meta fragment tag"

... i guess with all this set up i'm not sure how to test whether its working or not.

commented

sorry to be a pain but any idea as to what is going on?

You can verify that it works by putting ?_escape_fragment_= after the url in your browser.

commented

done that .. so what should happen?

All html that usually is generated by JavaScript should now be visible directly in the source.

A simple test: put <script>document.write('test')</script> in a view. Then, view the source of that page while visiting using the ?_escape_fragment_= suffix and the script should be replaced by just test.

commented

Yep! That seems to have done the trick.

Went back to ensure installation was right. Did try putting "<script>document.write('test')</script>" in a view and visit the URI with "?escape_fragment=" suffix...so that it looks like this "example.com/?escape_fragment=" sure enough it says "TEST". I assume this is working then.

But then when I visit "example.com/#!/" i still see "TEST" is this the way its suppose to be? Just to be sure.

Thanks again

I don't get it. What exactly did you put in the view? You said "".

commented

i put "document.write('TEST')" inside script tags without the quotes of course...and yes i'm able to see the word "TEST" displayed on page (again without quotes). So is that the indication to say its working then?

Another thing is that in my prerender.io account i added pages to be cached and when i click on "raw html" button, i notice my pages on display. I am led to believe it is working.

You have to open de source of the page (right click, view source) and verify that there are no script tags anymore, but only the word TEST.

commented

Well, when I do that I see neither script tags nor the word TEST. I only see source of my layout.blade.php... in other word tags for the layout.blade.php html. I'm confused.

Yeah ok, but somewhere in the HTML is the word TEST, right..?

commented

no mate. There is no TEST in HTML. I even put it in capitals with exclamation points to make it visibly clear but nothing at all.

But.. you said that you were able to see TEST displayed on the page.. Then it must be somewhere in the source, right?

commented

Yes, I still I'm able to see the word TEST on page. But when i right click and view source i can't find it there. Tried to even look line by line, top to bottom ... can't find it. If i inspect element on the displayed word TEST i can see it between body tags only and no other tags around it.

Note that the suffix must be ?_escape_fragment_=, not ?escape_fragment=.

Feel free to send me an email at todd@prerender.io. I'm happy to help test and make sure things are set up correctly.

commented

Hi @jeroennoten, I've tried that ?_escape_fragment_= but same result.

commented

Hi @thoop, thanks for getting back to me through email. Here is my configuration:

here's my .env:
PRERENDER_TOKEN=my_token
PRERENDER_URL=my_domain
PRERENDER_ENABLE=true

I run require nutsweb/laravel-prerender at the command prompt and this line was added to "require" section of composer.json like so:

"nutsweb/laravel-prerender": "^2.0"

And in config/app.php i have added this line:

'Nutsweb\LaravelPrerender\LaravelPrerenderServiceProvider',

And i did run:

$ php artisan vendor:publish

And this created a file prerender.php inside config folder like so:

config/prerender.php

I did not do anything to this file: add or delete

That's pretty much it.

Sorry to bump this issue, but I'm having the similar difficulty.

I successfully installed composer dependency and installed prerender.

However, it doesn't fetch from prerender service on my localserver.

The service is working perfectly fine. When I run http://example.com:3000/http://example.com, I get the pre-rendered content however when I run it like http://example.com?_escape_fragment_=/test, it still gives me the regular website with all scripts and styles.

My config is

PRERENDER_ENABLE=true
PRERENDER_URL=http://localhost

@tenzopro @thoop How did you resolve it?


Edit:
I managed to resolve the issue after spending a couple of hours.

  • It should be _escaped_fragment_ not _escape_fragment_
  • I should add port to url i.e. PRERENDER_URL=http://localhost:3000

Then it works fine.

Thanks