{"id":19982391,"url":"https://github.com/netlify/prerender","last_synced_at":"2025-04-05T05:08:10.634Z","repository":{"id":46064469,"uuid":"44230953","full_name":"netlify/prerender","owner":"netlify","description":"Automatically rendering JS-driven pages for crawlers and social sharing","archived":false,"fork":false,"pushed_at":"2024-11-25T07:38:36.000Z","size":759,"stargazers_count":101,"open_issues_count":12,"forks_count":13,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-04T13:25:25.633Z","etag":null,"topics":[],"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/netlify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-14T07:22:31.000Z","updated_at":"2024-12-30T13:02:40.000Z","dependencies_parsed_at":"2024-05-15T23:43:39.924Z","dependency_job_id":"3d05d91e-95fe-4296-8444-143f9cf9f1cb","html_url":"https://github.com/netlify/prerender","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fprerender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fprerender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fprerender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fprerender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netlify","download_url":"https://codeload.github.com/netlify/prerender/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243526954,"owners_count":20305115,"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":[],"created_at":"2024-11-13T04:11:05.759Z","updated_at":"2025-03-14T05:04:46.177Z","avatar_url":"https://github.com/netlify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nFacebook, Twitter, Yahoo, and Bing are constantly trying to view your website... but they don't execute javascript. That's why Prerender was built. Prerendering is useful for AngularJS SEO, BackboneJS SEO, EmberJS SEO, and any other javascript framework.\n\nBehind the scenes, Prerender is a node server forked from [prerender.io](http://prerender.io) that uses headless chrome to create static HTML out of a javascript page. Netlify hosts this as a service which you can configure in our UI to work automatically with your page.\n\nPrerender adheres to google's `_escaped_fragment_` proposal, which we recommend you use. It's straightforward:\n- add \u0026lt;meta name=\"fragment\" content=\"!\"\u003e to the \u0026lt;head\u003e of all of your pages\n- If you use hash urls (#), change them to the hash-bang (#!)\n- Turn on prerendering in the Netlify Build \u0026 Deploy Settings\n- That's it! Perfect SEO on javascript pages.\n\n\n## How it works\nThis is a simple service that only takes a url and returns the rendered HTML (with all script tags removed).\n\nNote: you should proxy the request through your server (using middleware) so that any relative links to CSS/images/etc still work.  If you don't, you'll see the relative links fail but the HTML output will still be useful for debugging purposes.\n\n## Running locally\nIf you are trying to test Prerender with your website on localhost, you'll have to run the Prerender server locally so that Prerender can access your local dev website.\n\n\t$ git clone https://github.com/netlify/prerender.git\n\t$ cd prerender\n\t$ npm install\n\t$ npm start\n\nPrerender will now be running on http://localhost:3000 and you can test your page (deployed on netlify or elsewhere!) using links like this:\n\nhttp://localhost:3000/https://www.netlify.com/pricing\n\nYou will see debug output in the shell you're running the service in that may help you in debugging why rendering isn't working as you're expecting.\n\n\n## Options\n\n### workers\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    workers: 1\n});\n\nserver.start();\n```\n\nThe number of Prerender workers that you'd like to start. We suggest 1 per CPU on your machine. `Default: os.cpus().length`\n\n### iterations\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    iterations: 40\n});\n\nserver.start();\n```\n\nThe number of pages Prerender should render before restarting the worker. WARNING: Will restart Prerender mid-request if two requests are in flight, causing a 504 response to be sent.\n\nShutting Prerender down reclaims memory to ensure good performance. You can also set the environment variable of `NUM_ITERATIONS` instead of passing in the `iterations` parameter. `Default: 40`\n\n### softIterations\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    softIterations: 5\n});\n\nserver.start();\n```\n\nThe number of pages Prerender should render before restarting the worker. This option counts the number of requests in flight and only restarts the worker if no requests are in flight. If you constantly have more than 1 request in flight, this won't restart the server.\n\nShutting Prerender down reclaims memory to ensure good performance. You can also set the environment variable of `NUM_SOFT_ITERATIONS` instead of passing in the `softIterations` parameter. `Default: 30`\n\n### cookiesEnabled\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    cookiesEnabled: true\n});\n\nserver.start();\n```\n\nIf Prerender should use Cookies. You can also set the environment variable of `COOKIES_ENABLED` instead of passing in the `cookiesEnabled` parameter. `Default: false`\n\n### logRequests\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    logRequests: true\n});\n\nserver.start();\n```\n\nCauses the Prerender server to print out every request made represented by a `+` and every response received represented by a `-`. Lets you analyze page load times. `Default: false`\n\n### pageDoneCheckTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    pageDoneCheckTimeout: 300\n});\n\nserver.start();\n```\n\nNumber of milliseconds between the interval of checking whether the page is done loading or not. You can also set the environment variable of `PAGE_DONE_CHECK_TIMEOUT` instead of passing in the `pageDoneCheckTimeout` parameter. `Default: 300`\n\n### resourceDownloadTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    resourceDownloadTimeout: 10000\n});\n\nserver.start();\n```\n\nNumber of milliseconds to wait while downloading the page, waiting for all pending requests/ajax calls to complete before timing out and continuing on. Time out condition does not cause an error, it just moves on to the javascript execution stage. You can also set the environment variable of `RESOURCE_DOWNLOAD_TIMEOUT` instead of passing in the `resourceDownloadTimeout` parameter. `Default: 10000`\n\n### waitAfterLastRequest\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    waitAfterLastRequest: 500\n});\n\nserver.start();\n```\n\nNumber of milliseconds to wait after the number of requests/ajax calls in flight reaches zero. Javascript execution begins after this in order to pull the HTML off of the page. You can also set the environment variable of `WAIT_AFTER_LAST_REQUEST` instead of passing in the `waitAfterLastRequest` parameter. `Default: 500`\n\n### jsTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    jsTimeout: 10000\n});\n\nserver.start();\n```\n\nNumber of milliseconds to continue trying to pull the HTML off of the page using javascript before timing out. Once the timeout is hit, Prerender returns a 200 response with the last HTML that it was able to pull off of the page. You can also set the environment variable of `JS_TIMEOUT` instead of passing in the `jsTimeout` parameter. `Default: 10000`\n\n### jsCheckTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    jsCheckTimeout: 300\n});\n\nserver.start();\n```\n\nNumber of milliseconds between the interval of checking whether the javascript timeout has been reached or not. You can also set the environment variable of `JS_CHECK_TIMEOUT` instead of passing in the `jsCheckTimeout` parameter. `Default: 300`\n\n### noJsExecutionTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    noJsExecutionTimeout: 3000\n});\n\nserver.start();\n```\n\nNumber of milliseconds to wait while not being able to execute javascript before determining that the Prerender server hasn't been able to execute javascript, usually due to a webpage not giving up control of the JS execution thread (infinite loop). You can also set the environment variable of `NO_JS_EXECUTION_TIMEOUT` instead of passing in the `noJsExecutionTimeout` parameter. `Default: 3000`\n\n### evaluateJavascriptCheckTimeout\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    evaluateJavascriptCheckTimeout: 300\n});\n\nserver.start();\n```\n\nNumber of milliseconds between executing the javascript on the webpage to pull off the HTML. Pulling off the HTML only happens multiple times when `window.prerenderReady` is set to false. You can also set the environment variable of `EVALUATE_JAVASCRIPT_CHECK_TIMEOUT` instead of passing in the `evaluateJavascriptCheckTimeout` parameter. `Default: 300`\n\n## Plugins\n\nWe use a plugin system in the same way that Connect and Express use middleware. Our plugins are a little different and we don't want to confuse the prerender plugins with the [prerender middleware](#middleware), so we opted to call them \"plugins\".\n\nPlugins are in the `lib/plugins` directory, and add functionality to the prerender service.\n\nEach plugin can implement any of the plugin methods:\n\n####`init()`\n\n####`beforePhantomRequest(req, res, next)`\n\n####`onPhantomPageCreate(phantom, req, res, next)`\n\n####`afterPhantomRequest(req, res, next)`\n\n####`beforeSend(req, res, next)`\n\n## Available plugins\n\nYou can enable the plugins in `server.js` by uncommenting the corresponding lines.\n\n### basicAuth\n\nIf you want to only allow access to your Prerender server from authorized parties, enable the basic auth plugin.\n\nYou will need to add the `BASIC_AUTH` environment variable. This is a CSV of username:password pairs:\n```\nexport BASIC_AUTH=u1:p1,u1:p2,u2:p3\n```\n\nThen make sure to pass the basic authentication headers.\n\n``` \ncurl -u prerender:wrong http://localhost:1337/http://example.com -\u003e 401\ncurl -u u1:p2 http://localhost:1337/http://example.com -\u003e 200\n\n\n# or if you want to explicitly set the header\n\necho -n \"u1:p2\" | base64\n# dTE6cDI=\n\ncurl -H \"Authorization: Basic dTE6cDI=\" http://localhost:1337/http://example.com\n```\n\n### removeScriptTags\n\nWe remove script tags because we don't want any framework specific routing/rendering to happen on the rendered HTML once it's executed by the crawler. The crawlers may not execute javascript, but we'd rather be safe than have something get screwed up.\n\nFor example, if you rendered the HTML of an angular page but left the angular scripts in there, your browser would try to execute the angular routing and rendering on a page that no longer has any angular bindings.\n\nThis plugin implements the `beforeSend` funtion, therefore cached HTML pages still contain scripts tags until they get served.\n\n### httpHeaders\n\nIf your Javascript routing has a catch-all for things like 404's, you can tell the prerender service to serve a 404 to google instead of a 200. This way, google won't index your 404's.\n\nAdd these tags in the `\u003chead\u003e` of your page if you want to serve soft http headers. Note: Prerender will still send the HTML of the page. This just modifies the status code and headers being sent.\n\nExample: telling prerender to server this page as a 404\n```html\n\u003cmeta name=\"prerender-status-code\" content=\"404\"\u003e\n```\n\nExample: telling prerender to serve this page as a 302 redirect\n```html\n\u003cmeta name=\"prerender-status-code\" content=\"302\"\u003e\n\u003cmeta name=\"prerender-header\" content=\"Location: http://www.google.com\"\u003e\n```\n\n### whitelist\n\nIf you only want to allow requests to a certain domain, use this plugin to cause a 404 for any other domains.\n\nYou can add the whitelisted domains to the plugin itself, or use the `ALLOWED_DOMAINS` environment variable.\n\n`export ALLOWED_DOMAINS=www.prerender.io,prerender.io`\n\n### blacklist\n\nIf you want to disallow requests to a certain domain, use this plugin to cause a 404 for the domains.\n\nYou can add the blacklisted domains to the plugin itself, or use the `BLACKLISTED_DOMAINS` environment variable.\n\n`export BLACKLISTED_DOMAINS=yahoo.com,www.google.com`\n\n\n### \u003ca id='s3-html-cache'\u003e\u003c/a\u003e\n### s3HtmlCache\n\nA `GET` request will check S3 for a cached copy. If a cached copy is found, it will return that. Otherwise, it will make the request to your server and then persist the HTML to the S3 cache.\n\nA `POST` request will skip the S3 cache. It will make a request to your server and then persist the HTML to the S3 cache. The `POST` is meant to update the cache.\n\nYou'll need to sign up with Amazon Web Services and export these 3 environment variables.\n\n```\n$ export AWS_ACCESS_KEY_ID=\u003caws access key\u003e\n$ export AWS_SECRET_ACCESS_KEY=\u003caws secret access key\u003e\n$ export S3_BUCKET_NAME=\u003cbucket name\u003e\n```\n\nWarning! Your keys should be kept private and you'll be charged for all files uploaded to S3.\n\n\u003e If Prerender is hosted on a EC2 instance, you can also take advantage of [IAM instance roles](http://aws.typepad.com/aws/2012/06/iam-roles-for-ec2-instances-simplified-secure-access-to-aws-service-apis-from-ec2.html)\nso that you don't need to export your AWS credentials.\n\n\u003e You can also export the S3_PREFIX_KEY variable so that the key (which is by default the complete requested URL) is\nprefixed. This is useful if you want to organize the snapshots in the same bucket.\n\n#### Region \n\n\nBy default, s3HtmlCache works with the US Standard region (East), if your bucket is localized in another region you can config it with an environment variable : `AWS_REGION`.\n\n```\n$ export AWS_REGION=\u003cregion name\u003e\n```\n\nFor example :\n\n```\n$ export AWS_REGION=eu-west-1\n```\n\n### inMemoryHtmlCache\n\n*Note* The in memory cache is per process so if you have multiple Prerender workers then they do not share a cache. For higher traffic websites, use a common cache like redis.\n\nAn in memory cache but you can easily change it to any caching system compatible with the `cache-manager` nodejs package.\n\nFor example, with the request:\n\n`GET http://service.prerender.io/https://www.facebook.com/`\n\nFirst time: Overall Elapsed:\t00:00:03.3174661\n\nWith cache: Overall Elapsed:\t00:00:00.0360119\n\n\n### logger\n\nThis will show console.log's from the phantomjs page in your local console. Great for debugging.\n\n### mongodbCache\n\nCaches pages in a MongoDB database. Available at [prerender-mongodb-cache](https://github.com/lammertw/prerender-mongodb-cache) by [@lammertw](https://github.com/lammertw)\n\n\n### memjsCache\n\nCaches pages in a memjs(memcache) service. Available at [prerender-memjs-cache](https://github.com/lammertw/prerender-memjs-cache) by [@lammertw](https://github.com/lammertw)\n\n\n### levelCache\n\nCaches pages in a levelDB database. Available at [prerender-level-cache](https://github.com/maxlath/prerender-level-cache) by [@maxlath](https://github.com/maxlath)\n\n### accessLog\n\nCreate access log file for prerendered requests. Available at [prerender-access-log](https://github.com/unDemian/prerender-access-log) by [@unDemian](https://github.com/unDemian)\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Todd Hooper \u0026lt;todd@prerender.io\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify%2Fprerender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetlify%2Fprerender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify%2Fprerender/lists"}