惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
V
Vulnerabilities – Threatpost
C
Cisco Blogs
A
Arctic Wolf
L
LINUX DO - 热门话题
P
Proofpoint News Feed
Security Latest
Security Latest
AWS News Blog
AWS News Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
W
WeLiveSecurity
爱范儿
爱范儿
Last Week in AI
Last Week in AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
PCI Perspectives
PCI Perspectives
C
Cybersecurity and Infrastructure Security Agency CISA
Spread Privacy
Spread Privacy
IT之家
IT之家
月光博客
月光博客
云风的 BLOG
云风的 BLOG
宝玉的分享
宝玉的分享
J
Java Code Geeks
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
I
Intezer
博客园_首页
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Palo Alto Networks Blog
NISL@THU
NISL@THU
Recent Commits to openclaw:main
Recent Commits to openclaw:main
有赞技术团队
有赞技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
量子位
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Security @ Cisco Blogs
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
V
V2EX
Jina AI
Jina AI

CloudCannon Blog

Building with AI: Git-based vs headless vs traditional CMS CloudCannon + Astro: performance meets powerful content management Introducing the Astro Component Starter Introducing Jetstream — built on the Astro Component Starter Why we switched to the system font stack Redesigning CloudCannon’s docs with Diátaxis, Lume, and Pagefind Make content editing more visual: upgraded Editable Regions How Configuration Mode makes building editing interfaces easy Your hosting just got an upgrade (and a price cut) Custom testing domains for professional branding Keep your content consistent with input validation Managing multilingual content in CloudCannon Simplify team publishing with conflict resolution and domain tools Open Beta: Publishing Conflict Resolution Getting started with CloudCannon and Astro: Bookshop, components, and live editing Welcome to the CloudCannon Community! Omnichannel delivery is just marketing spin from API-based CMS companies Getting started with CloudCannon and Astro: Snippets and Collections Managing digital assets in CloudCannon: a guide to smart asset storage Understanding CloudCannon's branching workflows and Projects: a complete guide What is a static website? CloudCannon’s 2024 wrapped Getting started with CloudCannon and Astro: WYSIWYG blogging Jamstack vs. WordPress: reasons to make the change The top five static site generators for 2025 (and when to use them!) Free Jekyll themes for 2025: ten great community options Eleventy (11ty) vs. Hugo How to set up WYSIWYG editing with MkDocs Material The rise of static-first websites: why major brands are making the switch Watching your Core Web Vitals on Jamstack Understanding the difference between static, dynamic, and hybrid websites Looking for an alternative to Netlify CMS or Decap CMS? Designing components for your website editors: a CloudCannon case study Does my website look big in this? Six tips to lower your page weight Content is sacred — so own your revision history The eternal balancing act: load time vs. delay time Streamlined Headless Mode, Unified Configuration, and live data editing What is a headless CMS? Looking for a TinaCMS or Tina Cloud alternative? The ultimate guide to Hugo Sections Coming soon: Live config editing and data reloading Faster publishing workflows out now! Why information architecture matters for your website Website UX vs SEO: picking your battles Easily manage your multilingual Astro site in CloudCannon How you can optimize publishing workflows for your content team How you can optimize your CMS for SEO success How you can optimize your Content Editor for long-form articles How you can optimize your Visual Editor for page building Secure, swift, and stable: static sites for the financial sector Enhanced flexibility for teams with Custom Permissions Building static sites that scale The Inaugural 11ty International Symposium on Making Web Sites Real Good How to manage hundreds of connected websites with a Git-based headless CMS How we’re building CloudCannon for accessibility CloudCannon’s new editing improvements are here! Open Beta | New ways to collaborate on editing your websites Top 11 free Eleventy themes for 2024 Top 10 free Astro themes to use in 2024 Why choose a Git-based headless CMS over a monolithic DXP in 2024? Learning web development: a self-guided roadmap Partner Site of the Month: Blüthner Piano Centre, by Winteractive CloudCannon’s 2023 wrapup Let’s create a microblog with visual editing using Bookshop and Eleventy Update and visualize your branches with CloudCannon Projects What is a Git-based CMS and why you should use one CloudCannon secures SOC 2 certification The complete guide to growing your web development agency Automatically optimize your images with Eleventy Image and CloudCannon Share components and syndicate content with Site Mounting Partner Site of the Month: Cru Uncorked, by Ed Meehan New web component for responsive HTML tables Wrapping up HugoConf 2023 Partner Site of the Month: Van Dillen Antieke Bouwmaterialen, by Fulldev How to become a freelance web developer: a comprehensive guide Q3 2023: CloudCannon features and improvements 22 ways to deliver more value to your web development clients Partner Site of the Month: DC Gay Flag Football League, by Ed Cupaioli A new way to configure your CloudCannon sites CloudCannon — the official CMS partner of Eleventy Full CloudCannon support for Nuxt static sites Partner Site of the Month: Stadium Bike, by Insight Creative, Inc. HugoConf 2023, brought to you by CloudCannon DAM Support for Cloudflare R2 and DigitalOcean Spaces Eleventy (11ty) vs. Gatsby in 2023 – which SSG is best for you? How CloudCannon’s live editing works with Astro and Bookshop Partner Site of the Month: Fiducian, by Croissant & Baguette Eleventy (11ty) vs. Astro How to customize CloudCannon’s Client Sharing interface Let anyone, anywhere, edit your CloudCannon sites Top 23 free Astro themes for building out-of-this-world static sites in 2023 How Jampack optimizes our Eleventy website and improves performance Astro vs. Next.js CloudCannon.com is now built with Eleventy! Out-of-this-world support for all Astro users Introducing the CloudCannon Partner Program Full CloudCannon support for Gatsby Top 10 Free SvelteKit Themes for Building Lighting-Fast Static Sites in 2023 Enhanced CloudCannon support for Next.js users Upcoming CloudCannon Interface improvements (Open Beta)
Bundling JavaScript for Jekyll
2020-11-12 · via CloudCannon Blog

Optimising assets can significantly improve load times for visitors to your site. When you build a site on CloudCannon, any assets referenced in your HTML/CSS are automatically minified and served from a CDN. JavaScript files are minified using UglifyJS.

In some cases, you may also want to bundle your JavaScript files together, to reduce the number of HTTP requests made when loading a page. The simplest solution would be to write all your code in a single file, but this compromises maintainability. Instead, you can use various techniques to bundle your files together on build for performance, while keeping them separate during development for sanity.

Jekyll includes Direct link to this section

A simple technique for bundling JavaScript is to use Jekyll includes. With this approach, a single JavaScript file would use {% include %} tags to include other scripts. For example, you could create a bundle.js file with the following:

---
---
{% include /assets/script-1.js %}
{% include /assets/script-2.js %}

Remember to add front matter dashes in bundle.js so that Jekyll processes the Liquid.

This allows you to divide your JavaScript into manageable pieces in development, while only linking to bundle.js on your site:

<script src="{{ site.baseurl }}/js/bundle.js"></script>

Note that if you don't want to keep all your scripts in the _includes folder, you can use the include_relative tag. This will allow you to specify a path relative to the file where the tag is being used (you cannot access higher-level directories however). For better readability, you might also want to keep your includes in the front matter and use Liquid to manage the include tags.

For example, if you are working in /js/bundle.js and your JavaScript files are in /js/scripts/, you could use the following:

---
dir_path: scripts/
scripts:
  - script-1.js
  - script-2.js
---
{% for script in scripts %}
    {% assign script_path = dir_path | append: script %}
    {% include_relative script_path %}
{% endfor %}

Bear in mind that the scripts are simply being concatenated, so you will need to be mindful of conflicting variable names. You can avoid this problem by wrapping each script in a function that is called as soon as it is defined (i.e. an IIFE). Variables within the function cannot be accessed from outside of it, so there won't be any conflicting variables between the included scripts.

---
dir_path: scripts/
scripts:
- script-1.js
- script-2.js
---
{% for script in scripts %}
{% assign script_path = dir_path | append: script %}
(function () {
{% include_relative script_path %}
})();
{% endfor %}

Using webpack Direct link to this section

webpack is a JavaScript bundler. It searches your code for dependencies and bundles scripts together in a single file. First, install webpack:

$ npm install webpack
$ npm install webpack-cli

On the command line, specify each JavaScript file you want to bundle, then specify the destination for the bundle with -o path/to/output.js. For example:

$ node_modules/.bin/webpack js/file-1.js \
js/file-2.js \
js/file-3.js \
-o js/output.js

This will bundle all your scripts into one file. In your <script> tags, you can simply link to the bundled file:

<script src="{{ site.baseurl }}/js/output.js"></script>

Instead of specifying each input file on the command line, you can create an entry.js file. This file should just require/import all the scripts you want to bundle. Then, you can use this as your input and all of the other imported scripts will be bundled.

$ ./node_modules/.bin/webpack path/to/entry.js -o js/output.js

This is very basic use of webpack - see the webpack docs for more configuration options.

Using Gulp Direct link to this section

Gulp is a JavaScript toolkit for automating tasks. You can use this with the gulp-concat package to bundle your JavaScript files together.

First, create a package.json by running npm init. Then install gulp and gulp-concat and add them to your project dev dependencies:

$ npm install --save-dev gulp
$ npm install --save-dev gulp-concat

Create a gulpfile.js at the root of your project with the following:

const gulp = require('gulp');
const concat = require('gulp-concat');

gulp.task('concat-scripts', function() {
return gulp.src('./input-scripts/*.js')
.pipe(concat('output.js'))
.pipe(gulp.dest('./assets/'));
});

gulp.task defines a task called "concat-scripts". This task uses gulp.src to read in all JavaScript files from an /input-scripts/ directory. The scripts are concatenated into an output.js file, which is then saved into the /assets/ directory using gulp.dest.

You can run this task from the command line in your project directory with gulp concat-scripts. Then you can simply link to /assets/output.js on your site:

<script src="{{ site.baseurl }}/assets/output.js"></script>

If you want to minify your script after bundling it, you can do this easily with gulp-uglify. This will reduce the size of your bundled script, to improve performance for visitors to your site.

$ npm install --save-dev gulp-uglify
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');

gulp.task('concat-and-minify-scripts', function() {
return gulp.src('./input-scripts/*.js')
.pipe(concat('output.js'))
.pipe(uglify())
.pipe(gulp.dest('./assets/'));
});

Prebuild commands in CloudCannon Direct link to this section

CloudCannon supports custom commands, so that you can use tools like Gulp and webpack easily. Simply create a _cloudcannon-prebuild.sh file at the root of your project with any commands you want to run before each site build.

Your prebuild commands run in a Node environment, so you can install any npm packages you need.

For example:

npm install webpack
npm install webpack-cli

./node_modules/.bin/webpack path/to/entry.js -o js/output.js

npm install gulp
npm install gulp-concat

./node_modules/.bin/gulp concat-task

Prebuild commands allow you to incorporate your favourite tools for building and pre-processing into CloudCannon. Bundling JavaScript is just one way to use this functionality - other uses could include fetching API data, running build commands other than Jekyll, or sending messages to your Slack channel.