npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ajs-express

v1.1.1

Published

ExpressJS Middleware for AjaxSnapshots

Downloads

13

Readme

ExpressJS Middleware for AjaxSnapshots

Many modern websites have a substantial part of their HTML content generated in the browser using Javascript. This is the case for sites built with AngularJS, EmberJS, BackboneJS and Sencha Touch.

Search engines like Google aren't good at indexing these sites because they don't run the Javascript before indexing their pages. Social network bots like those from Facebook and Twitter have similar problems when they try to create a preview of a shared page that is generated using Javascript.

Fortunately Google came up with a solution to this problem: The Crawlable AJAX Specification. This provides a safe way for sites to provide Google with snapshots of their pages' HTML after all necessary Javascript has run. This specification has been widely adopted and is supported by Bing, Yandex and some social bots.

AjaxSnapshots makes it easy to start using the The Crawlable AJAX Specification by providing a SaaS based implemention that's easy to plug in at web server level.

This project provides ExpressJS Middleware that lets you add The Crawlable AJAX Specification to an ExpressJS (on NodeJS) based website in a few lines of code.

##SEO enabling and ExpressJS site

####Prerequisistes:

For full details see our configuration guide. Here is a summary of the prerequisites.

If your site uses hash # based URLs like http://mysite.com#mypage change this so that you are using hashbang #! URLs like http://mysite.com#!mypage instead. If you have sitemap.xml file make sure it contains the hashbang URLs too, rathe than the old hash based ones.

If your site uses hashless, e.g. pushState() based URLs add the following header to all of you pages.

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

####ExpressJS Configuration

First install the AjaxSnapshots ExpressJS module

$ npm install ajs-express --save

Then in your ExpressJS code import the module, configure it with your API Key (from your account page) and use the middleware.

var ajs = require('ajs-express');

//set api key
ajs.set('apikey','put-your-apikey-here');

//use the middleware (add this to your app early to make sure 
//everything that should be snapshotted is)
app.use(ajs);

That's all!

####Configuration Options

This section covers several other configuration options you can use. For a fuller discussion see our API Documentation.

All configuration options are set using the set method. This can take a key-value pair or a configuration object as follows:

var ajs = require('ajs-express');

//key-value based configuration
ajs.set('foo','bar');
ajs.set('baz','elf');

//equivalent config-object based configuration
ajs.set({
  foo:'bar',
  baz:'elf'
});

The available configuration options are:

  • apikey (mandatory) Your API Key (it's on your account page)
  • snap-time (default: 5000) This lets you specify how long in milliseconds we should wait after the page's onload event fires before we take the snapshot. Note that the snapshot will be taken earlier than this if either our on-page Javascript API is used to specify an exact time for the snapshot or 40 seconds has elapsed since we started loading your page.
  • remove-hidden (default: true) If true then all hidden elements in the page body except for scripts and stylesheets will be removed before returning the snapshot. The term hidden is defined as per the :hidden JQuery 2.0 selector, except that we do not remove head, meta, link, style or title elements.
  • remove-selector (default: undefined) If set this is should be a valid JQuery 2.0 selector. All matching elements on your page will be removed before returning the snapshot.
  • device-width (default: 1280) Sets the width in pixels of the headless browser used to render your page. Setting this can be important when you are using responsive pages that show different content at different page sizes.
  • device-height (default: 800) Sets the height in pixels of the headless browser used to render your page. Setting this can be important when you are using responsive pages that show different content at different page sizes.

####Learn More

For more on how to get your AngularJS, EmberJS, BackBoneJS, Sencha or other Javascript sites properly indexed by Google and other search engines visit us a https://ajaxsnapshots.com