{"id":16466934,"url":"https://github.com/itbdw/server-render-javascript","last_synced_at":"2025-03-23T11:32:38.754Z","repository":{"id":146115828,"uuid":"98041566","full_name":"itbdw/server-render-javascript","owner":"itbdw","description":"Prerender your javascript web page for better seo with PhantomJS. ⚠️ no es6 supported.","archived":false,"fork":false,"pushed_at":"2020-10-14T16:14:25.000Z","size":23,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T19:55:06.929Z","etag":null,"topics":["prerender","seo","server-rendering"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itbdw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-22T15:51:47.000Z","updated_at":"2022-09-25T15:42:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"e3ab5476-852a-4fbc-aea7-0ba1a829771e","html_url":"https://github.com/itbdw/server-render-javascript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itbdw%2Fserver-render-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itbdw%2Fserver-render-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itbdw%2Fserver-render-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itbdw%2Fserver-render-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itbdw","download_url":"https://codeload.github.com/itbdw/server-render-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prerender","seo","server-rendering"],"created_at":"2024-10-11T11:45:17.943Z","updated_at":"2025-03-23T11:32:38.448Z","avatar_url":"https://github.com/itbdw.png","language":"JavaScript","readme":"\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n\n# WARNING\nThis is a thing waste of your time!\n\n# 警告\n纯属浪费时间，不要尝试。\n\n\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n:warning::warning::warning::warning::warning::warning::warning::warning::warning::warning:\n\n\n\n# server-render-javascript\nPrerender your javascript web page for better seo with PhantomJS.\n\n## Dependency\n\n Must \n\n`PhantomJS`, a server headless browser.\n\n`NodeJS`, serve phantomjs.\n\nSuggested\n\n`pm2`, start the server and much more.\n\n## Install\n\n\u003e Suppose you are using a Ubuntu Server and nginx as web server.\n\n1. NodeJS\n\n```\ncurl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -\n\nsudo apt-get install -y nodejs\n\n```\n\n2. PhantomJS\n\nGo [http://phantomjs.org/download.html](http://phantomjs.org/download.html) and download a latest version, extract it, cd the dir, and `mv bin/phantomjs /usr/bin`, that is all!\n\n3. Install and Run\n\nDownload this code to your server, say `/var/server/spider`, the directory\nstructure looks like below\n\n```\n/var/server/spider/\n                    craw.js\n                    package.json\n                    spider.js\n\n```\n\nAny thing within craw.js and spider.js can be modified for your actual need.\n\n```\ncd /var/server/spider\nnpm install\n\nPORT=3000 pm2 -f start spider.js\n```\n\nafter started, you can use `pm2 logs` to monitor logs, `pm2 list` to display services and much more.\n\n\n4. Proxy Request\n\nI suppose you use nginx as web server and run the nodejs and nginx at same server.\n\n```\nupstream spider {\n    server localhost:3000;\n}\n\nserver {\n    ...\n    \n    \n    set $is_spider 0;\n    set $is_server_render 0;\n\n    if ($http_user_agent ~ Baiduspider) {\n       set $is_spider 1;\n    }\n\n    if ($http_user_agent ~ Googlebot) {\n       set $is_spider 1;\n    }\n\n    if ($http_user_agent ~ ServerRender) {\n       set $is_server_render 1;\n    }\n\n    set $is_spider_is_render $is_spider$is_server_render;\n\n    location / {\n        ...        \n    \n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n\n        if ($is_spider_is_render = 10) {\n             proxy_pass http://spider;\n        }\n\n        ...\n    }\n    ...\n}\n```\n\nAfter changing nginx config, don't forget reload the nginx.\n\nYou can make a request and check your nginx access log if anything works great.\n\n`curl -A 'fake Googlebot by server-render-javascript' http://yourwebsite.com/abc`\n\nYou should get two line in nginx access log, one is your request with user-agent `fake Googlebot by server-render-javascript` and one made by\nyour upstream server with user-agent `ServerRenderJavascript`, if you have not change the default user-agent at craw.js.\n\n\n## Caution\n\n* Watch out the timeout in craw.js\n\n## What and how it works\n\nYour website is rendered with javascript. But search engine (like Baidu, Sogou, 360) does not like the page, and `even` can not understand javascript content totally.\n\n\nSo, why don't we run a browser on the server side. When spider like Googlebot comes to your website,\nproxy the request to a upstream server, why not `nodejs server`, and the upstream server deal the request\nwith a headless browser and make a new request just like the we human visit website by Safari or Chrome and return the\nrendered content back.\n\nThe workflow looks like this\n\n```\nGoogleBot =\u003e Web Server =\u003e NodeJS Server =\u003e Make A Request Again With Server Browser =\u003e Get Web Content And Return\n```\n\nIn fact, Chrome also support headless browse after version 59. But compared with PhantomJS for now, ~~PhantomJS is better and easy to use.~~ you can find a chrome version at [https://github.com/itbdw/server-render-javascript-chrome](https://github.com/itbdw/server-render-javascript-chrome)\n\n\n\n\n## Thanks\n\n[Prerender For SEO](https://www.mxgw.info/t/phantomjs-prerender-for-seo.html)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitbdw%2Fserver-render-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitbdw%2Fserver-render-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitbdw%2Fserver-render-javascript/lists"}