New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

frags

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frags

Conditionally load fragments of UI based on screen size.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

Frags

Conditionally load HTML fragments based on screen size.

How it works

Installation

You can download frags from this repo at /dist/frags.min.js, or install it via npm.

npm install frags

Include frags as a Node module (with something like Browserify), or with a script tag.

var frags = require('frags');

OR

<script src="/path/to/frags.js"></script>

Initialize frags with a class name of your choosing:

frags('js-fragment'); // Use the same class name for your fragments (see below)

Usage

Declare which pieces of your page should be loaded conditionally.

index.html

<h1>Fragments are cool</h1>

<div class="js-fragment" data-fragment-media="min-width:760" data-fragment-template="fragments/frag.html"></div>

// You can also use a max-width query: "max-width:760"

Create a fragment in a separate HTML file.

fragments/frag.html

<section class="frag">
  <h2>This is a fragment</h2>
  <p>Cool things are happening here.</p>
</section>

When the browser window reaches a minimum width of 760px, the contents of frag.html will replace the element in index.html:

Result (index.html):

<h1>Fragments are cool</h1>

<section class="frag">
  <h2>This is a fragment</h2>
  <p>Cool things are happening here.</p>
</section>

You can also include <script> tags in your fragments:

fragments/frag.html

<section class="frag">
  <h2>This is a fragment</h2>
  <p>Cool things are happening here.</p>

  <script src="/path/relative/to/index.html/script.js"></script>

  <script>
    console.log('Hello world');
  </script>
</section>

Script tags will be executed when the fragment has been downloaded and inserted into the calling page.

Keywords

FAQs

Package last updated on 19 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc