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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cable8mm/jquery-infinite-with-template

v1.1.2

Published

JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little library will help.

Readme

⚡ jQuery Infinite With Template Plugin

NPM Version npm bundle size NPM Downloads jsDelivr hits (npm) NPM Type Definitions NPM License GitHub stars GitHub issues

🚀 AJAX-powered infinite scroll with template rendering for jQuery

If you like jQuery until now, this little library will help you implement infinite scroll with ease.

✨ Features

  • Zero Dependencies (except jQuery & jsRender)
  • 🎨 Template Rendering with jsRender
  • 🔄 Dual Loading Modes - Scroll or Click
  • 🎯 TypeScript Support out of the box
  • 🛡️ Error Handling with callbacks
  • ⚙️ Highly Configurable with 12+ options
  • 🚀 Performance Optimized with DocumentFragment
  • 📦 Lightweight - Only ~3KB minified
  • Well Tested - 16 unit tests included

📦 Installation

npm

npm i @cable8mm/jquery-infinite-with-template

CDN

<script
  src="https://cdn.jsdelivr.net/npm/@cable8mm/[email protected]/jquery.infiniteScrollWithTemplate.min.js"
  integrity="sha256-bX3iyCp0T50YmDRgpUl1tY/LGlpPGsKR4TqUkpcq6WA="
  crossorigin="anonymous"
></script>

ESM

<script type="module">
  import @cable8mm/jquery-infinite-with-template from https://cdn.jsdelivr.net/npm/@cable8mm/[email protected]/+esm
</script>

🎬 Demo

Online Demo

You can test the plugin directly in your browser:

👉 https://www.palgle.com/jquery-infinite-with-template/examples/index.html

Quick Start

Using npm run dev (Recommended)

# Install dependencies (one-time)
npm install

# Run development server with auto-open
npm run dev

Note: This will start the server at http://127.0.0.1:8080/examples/index.html and automatically open it in your browser.

Visit http://127.0.0.1:8080/examples/index.html in your browser.

Regenerate Demo Data

# Using PHP CLI
php examples/generate > examples/data_sources.json

# Or if you have the generate script in examples directory
cd examples
php generate > data_sources.json

🚀 Usage

Basic Example

HTML:

<div id="result"></div>

<script id="test-tmpl" type="text/x-jsrender">
  <div class="item">
    <h3>{{:title}}</h3>
    <p>ID: {{:id}}</p>
  </div>
</script>

JavaScript:

$("#result").infiniteTemplate({
  templateSelector: "#test-tmpl",
  dataPath: "/api/posts",
  query: "category=tech",
  templateHelpers: {
    userId: 123,
  },
  zeroCallback: function () {
    console.log("No more posts!");
  },
});

Server Response (JSON):

{
  "data": [
    {
      "id": 1,
      "title": "Getting Started with jQuery",
      "content": "..."
    },
    {
      "id": 2,
      "title": "Advanced JavaScript Patterns",
      "content": "..."
    }
  ]
}

Click-to-Load Button

$("#result").infiniteTemplate({
  templateSelector: "#item-template",
  dataPath: "/api/items",
  loadSelector: "#load-more-btn", // Click this button to load more
  loadAtStart: false, // Don't load automatically
});

With Error Handling

$("#result").infiniteTemplate({
  templateSelector: "#item-template",
  dataPath: "/api/items",
  errorCallback: function (error) {
    console.error("Failed to load:", error);
    alert("Something went wrong. Please try again.");
  },
  loadingCallback: function () {
    $("#loading").show();
  },
  loadedCallback: function () {
    $("#loading").hide();
  },
});

📋 Options

| Option | Type | Default | Description | | -------------------- | ---------- | ------------ | ------------------------------------------------------------ | | templateSelector | string | required | jsRender template selector (e.g., "#my-template") | | dataPath | string | required | URL to load data via AJAX | | key | string | "data" | Key for data array in JSON response | | query | string | null | Additional query parameters (e.g., "category=1&sort=date") | | method | string | "GET" | HTTP method (GET, POST, PUT, DELETE) | | templateHelpers | object | null | Helper data merged with each item | | loadAtStart | boolean | true | Load data on initialization | | loadSelector | string | null | CSS selector for click-to-load button | | initialPage | number | 1 | Initial page number | | preventCache | boolean | false | Add timestamp to prevent caching | | scrollThreshold | number | 2 | Multiplier for viewport height (lower = more sensitive) | | zeroCallback | function | null | Called when no data returned on first page | | errorCallback | function | null | Called on AJAX or JSON parse error | | loadingCallback | function | null | Called when loading starts | | loadedCallback | function | null | Called when loading completes (success or error) |

🎯 Real-World Examples

Example 1: Blog Posts with Pagination

$("#post-list").infiniteTemplate({
  templateSelector: "#post-template",
  dataPath: "/api/posts",
  query: "status=published",
  initialPage: 1,
  scrollThreshold: 1.5,
  templateHelpers: {
    currentUser: window.currentUser,
  },
  loadingCallback: () => $("#spinner").show(),
  loadedCallback: () => $("#spinner").hide(),
  zeroCallback: () => $("#end-message").show(),
});

Example 2: E-commerce Product Grid

$("#product-grid").infiniteTemplate({
  templateSelector: "#product-card",
  dataPath: "/api/products",
  query: "category=electronics&sort=price",
  loadSelector: "#load-more-products",
  loadAtStart: true,
  templateHelpers: {
    currency: "$",
    discountRate: 0.1,
  },
});

Example 3: Social Media Feed

$("#feed").infiniteTemplate({
  templateSelector: "#feed-item",
  dataPath: "/api/feed",
  method: "POST",
  query: "filter=following",
  initialPage: 3,
  preventCache: true,
  templateHelpers: {
    currentUserId: Auth.id(),
    likedPosts: Auth.likedPosts(),
  },
});

Example 4: Search Results

$("#search-results").infiniteTemplate({
  templateSelector: "#result-item",
  dataPath: "/api/search",
  query: `q=${encodeURIComponent(searchQuery)}`,
  zeroCallback: () => {
    $("#no-results").show();
  },
  errorCallback: (error) => {
    console.error("Search failed:", error);
  },
});

🏗️ Project Structure

jquery-infinite-with-template/
├── jquery.infiniteScrollWithTemplate.js  # Main plugin (unminified)
├── jquery.infiniteScrollWithTemplate.min.js  # Minified version
├── jquery.infiniteScrollWithTemplate.d.ts  # TypeScript definitions
├── package.json
├── README.md
├── LICENSE
├── examples/
│   ├── index.html          # Demo page
│   ├── data_sources.json   # Demo data
│   └── generate            # Data generator script
└── tests/
    ├── setup.js            # Test configuration
    └── jquery.infiniteScrollWithTemplate.test.js  # 16 unit tests

🧪 Testing

# Install dependencies
npm install

# Run tests
npm test

Test Coverage:

  • ✅ Initialization & validation
  • ✅ Data loading & rendering
  • ✅ Callbacks (zero, error, loading, loaded)
  • ✅ Scroll & click loading modes
  • ✅ URL building & pagination
  • ✅ Edge cases (empty data, JSON parsing)

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Credits

  • jsRender - Template engine
  • jQuery - DOM manipulation

💡 Tips for Getting Stars

  • ⭐ Star this repo if you find it useful!
  • 🐛 Report bugs and request features
  • 📢 Share with your developer friends
  • 💬 Leave feedback and suggestions

🔗 Links


Made with ❤️ by Sam Lee

If this project helped you, please give it a ⭐️!