-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Add Shopify Theme Development Best Practices guide #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zjtdzyx
wants to merge
1
commit into
PatrickJS:main
Choose a base branch
from
zjtdzyx:feat/shopify-theme-dev-best-practices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| --- | ||
| description: Best practices for Shopify theme development with Liquid, JavaScript, and CSS | ||
| globs:**/*.liquid, assets/*.js, assets/*.css, sections/*.liquid, snippets/*.liquid, templates/**/*.liquid | ||
| --- | ||
|
|
||
|
|
||
| # Shopify Theme Development Best Practices | ||
|
|
||
| ## Project Structure | ||
| - Adopt a clear **directory structure**, e.g., `sections`, `snippets`, `templates`, `assets`. | ||
| - Organize **generic modules** (like JavaScript functionalities) into separate files. | ||
| - Keep **Liquid files** concise and focused on single responsibilities, avoiding monolithic files. | ||
| - Organize templates and sections by **page or functionality**. | ||
| - Implement proper **internationalization (i18n)** file management. | ||
| - Utilize **SCSS/CSS Modules** for style organization to prevent global pollution. | ||
|
|
||
| ## Liquid Templating | ||
| - Prefer the `render` tag over `include`. | ||
| - Limit **database queries** within loops to avoid N+1 issues. | ||
| - Use **filters** judiciously, especially complex computational ones. | ||
| - Leverage Liquid's **caching mechanisms** to reduce redundant calculations. | ||
| - Avoid complex **logic handling** directly in Liquid; move intricate logic to JavaScript. | ||
| - Use `assign` and `capture` to define and reuse variables effectively. | ||
|
|
||
| ## JavaScript Development | ||
| - Modularize JS, using **ES Modules** for imports and exports. | ||
| - Follow modern JavaScript **best practices**, such as `const`/`let`, arrow functions, etc. | ||
| - Avoid direct **DOM manipulation**; prioritize event delegation. | ||
| - Optimize **JavaScript performance** to reduce repaints and reflows. | ||
| - Consider using **Webpack/Rollup** for bundling and code optimization. | ||
| - Write clear **comments** and **JSDoc**. | ||
|
|
||
| ## CSS/SCSS Styling | ||
| - Adhere to naming conventions like **BEM, OOCSS, or Utility-First CSS**. | ||
| - Optimize **CSS selectors** to improve rendering performance. | ||
| - Use **CSS variables** to manage theme configurations like colors and fonts. | ||
| - Implement **responsive design** to ensure consistent theme appearance across devices. | ||
| - Minimize **CSS file size** by removing unused styles. | ||
| - Make good use of **SCSS mixins** and **functions**. | ||
|
|
||
| ## Sections and Blocks | ||
| - Utilize Section **Schema** to define configurable options. | ||
| - Maintain **section independence and reusability**. | ||
| - Provide clear **presets** for sections. | ||
| - Use **Blocks** appropriately to enhance section flexibility. | ||
| - Ensure sections provide a good user experience in the **Shopify Customizer**. | ||
| - Avoid hardcoding content within sections; use Schema configurations whenever possible. | ||
|
|
||
| ## Performance Optimization | ||
| - Optimize **image loading** by using Shopify's CDN and the `image_url` filter. | ||
| - Minify **JavaScript and CSS files**. | ||
| - Leverage **browser caching**. | ||
| - Reduce the number of **HTTP requests**. | ||
| - Consider **lazy loading**. | ||
| - Monitor **theme performance** using Google Lighthouse and Shopify Theme Check. | ||
|
|
||
| ## Accessibility (A11y) | ||
| - Ensure all interactive elements are **keyboard accessible**. | ||
| - Provide meaningful **`alt` text** for images. | ||
| - Use correct **HTML semantic tags**. | ||
| - Consider **color contrast**. | ||
| - Implement clear **focus states**. | ||
| - Use **ARIA attributes** to enhance the accessibility of complex components. | ||
|
|
||
| ## Maintenance and Scalability | ||
| - Write clear **code comments** and documentation. | ||
| - Follow **naming conventions** to maintain code consistency. | ||
| - Regularly **test** theme functionalities. | ||
| - Ensure compatibility across different **browsers and devices**. | ||
| - Consider future **extensibility**, avoiding tight coupling. | ||
| - Use **Shopify CLI** for local development and deployment. | ||
|
|
||
| ## Quality and Testing | ||
| - Use **Shopify Theme Check** for static code analysis. | ||
| - Write **unit tests** (where applicable). | ||
| - Conduct thorough **end-to-end testing**. | ||
| - Test in various environments (local, development store, production store). | ||
| - Focus on **compatibility testing** (browsers, devices, Shopify versions). | ||
| - Test **error handling** and edge cases. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Front-matter
globsfield is not valid YAML – parsing will failThe key/value pair is missing a space after the colon and should be an array (each glob quoted or indented). Broken front-matter prevents the rule engine or any static-site generator from reading the metadata.
📝 Committable suggestion
🤖 Prompt for AI Agents