Aim : I have a small shortener service. I use links generated using this services as part of the content I post on facebook. Facebook's URL scraper tries to generate a preview by locating the end-point URL and pull relevant information.
This, right now works because I simply redirect in PHP with the way it's mentioned below without allowing me to execute JS before that redirection. I want to find out if there is a way to execute that JS.
What can I do? Well! redirect from JS using window.location
like this solution here...
What's the problem? If I do that, Facebook's URL scraper can no longer find the final destination url, resulting in a blank preview of my site(specifically the page where JS executes) instead of the destination site. JS execution is a must so can't omit that.
Question : Is there a way I can execute some piece of javascript before I do a redirection via header location and still be able to get correct previews for URLs?
Reference Code - in Laravel Controller
if($row->save()){
//i was first doing this and doing a redirect from the view.
//return View::make('pages/redirect')->with('originalUrl',$row->url);
//but then i realized it wasn't fetching the previews. So i do this now.
return Redirect::to($row->url);
//assuming it internally uses php's header location. I want to use the JS before this redirect.
}