Deploy Backend / deploy (push) Successful in 2m35s
- Six new topic pairs (EN+FA): TypeScript advanced patterns, SQL indexes, Git branching/reviews, TDD, clean architecture in Laravel, browser page load - Every existing post gains Key takeaways + FAQ sections in both languages - New engineering-practices category pair and database/git/testing tag pairs - Single-post API now returns same-language previous_post/next_post links
2682 lines
258 KiB
PHP
2682 lines
258 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Blog;
|
|
|
|
use App\Models\Blog\Category;
|
|
use App\Models\Blog\Post;
|
|
use App\Models\Blog\Tag;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Replaces the faker-generated demonstration content with real, keyword-focused
|
|
* articles in both English and Persian.
|
|
*
|
|
* The blog stores posts in a single `posts` table with no locale column, so each
|
|
* article exists as its own row. Persian and English posts are twins under the
|
|
* hood (same topic, per-language label, title, slug, excerpt and body) and use
|
|
* per-language categories/tags whose slugs share a namespace.
|
|
*
|
|
* Safe to re-run: it wipes the blog tables (posts, relations, categories, tags)
|
|
* before inserting fresh deterministic content.
|
|
*
|
|
* Run it on the server with:
|
|
* php artisan db:seed --class=Database\\Seeders\\Blog\\RealBlogContentSeeder --force
|
|
*/
|
|
class RealBlogContentSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$author = User::find(1);
|
|
|
|
if (!$author) {
|
|
$this->command->error('User with id 1 not found.');
|
|
return;
|
|
}
|
|
|
|
// --- Wipe the demonstration content ----------------------------------
|
|
// Deletion order respects the foreign keys so no per-driver "disable
|
|
// checks" magic is needed: pivot rows first, then posts, then the
|
|
// standalone tag/category rows.
|
|
DB::table('related_posts')->delete();
|
|
DB::table('post_tag')->delete();
|
|
Post::query()->delete();
|
|
Tag::query()->delete();
|
|
Category::query()->delete();
|
|
|
|
// --- Categories ------------------------------------------------------
|
|
$categories = [
|
|
// English
|
|
['name' => 'Frontend Development', 'slug' => 'frontend-development', 'description' => 'Articles about modern frontend engineering: HTML, CSS, JavaScript and the tools that keep interfaces fast and maintainable.', 'short_description' => 'HTML, CSS, JavaScript and the tools behind fast interfaces.'],
|
|
['name' => 'React & Next.js', 'slug' => 'react-nextjs', 'description' => 'Deep dives into React, Next.js and the ecosystem around them: components, rendering, and real-world patterns.', 'short_description' => 'React, Next.js and the ecosystem around them.'],
|
|
['name' => 'Backend Development', 'slug' => 'backend-development', 'description' => 'Server-side code, APIs, databases and the design decisions behind reliable backends.', 'short_description' => 'APIs, databases and reliable server-side code.'],
|
|
['name' => 'DevOps & Deployment', 'slug' => 'devops-deployment', 'description' => 'Docker, CI/CD, hosting and everything between the commit and the production URL.', 'short_description' => 'Docker, CI/CD and shipping to production.'],
|
|
['name' => 'Programming Careers', 'slug' => 'programming-careers', 'description' => 'Interviews, learning paths and honest advice for people who write code for a living.', 'short_description' => 'Interviews, learning paths and honest career advice.'],
|
|
['name' => 'Web Performance & SEO', 'slug' => 'web-performance-seo', 'description' => 'Core Web Vitals, technical SEO and the measurements that make interfaces feel instant, stay findable and rank.', 'short_description' => 'Speed, Core Web Vitals and technical SEO that move rankings.'],
|
|
|
|
// Persian
|
|
['name' => 'Engineering Practices', 'slug' => 'engineering-practices', 'description' => 'Testing, clean code, version control and the habits that keep a codebase healthy as a team grows.', 'short_description' => 'Testing, clean code and the habits that keep codebases healthy.'],
|
|
['name' => 'مهندسی نرمافزار', 'slug' => 'engineering-practices-fa', 'description' => 'تست، کد تمیز، کنترل نسخه و عادتهایی که در رشد تیم، سلامت کد را حفظ میکنند.', 'short_description' => 'تست، کد تمیز و عادتهای سالم نگهداشتن کد.'],
|
|
['name' => 'توسعه فرانتاند', 'slug' => 'frontend-fa', 'description' => 'مقالههایی دربارهی مهندسی فرانتاند مدرن، از HTML و CSS تا جاوااسکریپت و ابزارهایی که رابطها را سریع و کاربرپسند نگه میدارند.', 'short_description' => 'HTML، CSS، جاوااسکریپت و ابزارهای ساخت رابطهای سریع.'],
|
|
['name' => 'ریاکت و نکست', 'slug' => 'react-nextjs-fa', 'description' => 'نگاه عمیق به ریاکت، نکست و اکوسیستم اطراف آنها؛ کامپوننتها، رندرینگ و الگوهای کاربردی.', 'short_description' => 'ریاکت، نکست و اکوسیستم اطراف آنها.'],
|
|
['name' => 'توسعه بکاند', 'slug' => 'backend-fa', 'description' => 'کد سمت سرور، APIها، پایگاهداده و تصمیمهایی که پشت یک بکاند قابل اتکا گرفته میشود.', 'short_description' => 'APIها، پایگاهداده و کد سمت سرور قابل اتکا.'],
|
|
['name' => 'دواپس و استقرار', 'slug' => 'devops-fa', 'description' => 'داکر، CI/CD، هاستینگ و هر چیزی که بین کامیت و URL تولید فاصله میاندازد.', 'short_description' => 'داکر، CI/CD و رساندن کد به سرور تولید.'],
|
|
['name' => 'مسیر شغلی برنامهنویسی', 'slug' => 'career-fa', 'description' => 'مصاحبهها، نقشههای یادگیری و توصیههای صادقانه برای کسانی که برنامهنویسی شغل آنهاست.', 'short_description' => 'مصاحبه، نقشه یادگیری و توصیههای شغلی صادقانه.'],
|
|
['name' => 'پرفورمنس وب و سئو', 'slug' => 'web-performance-seo-fa', 'description' => 'شاخصهای Core Web Vitals، سئو تکنیکال و اندازهگیریهایی که رابطها را سریع، پیداشدنی و کاربرپسند میکنند.', 'short_description' => 'سرعت، Core Web Vitals و سئو تکنیکال موثر.'],
|
|
];
|
|
|
|
$categoryIds = [];
|
|
foreach ($categories as $category) {
|
|
$created = Category::create([
|
|
'name' => $category['name'],
|
|
'slug' => $category['slug'],
|
|
'description' => $category['description'],
|
|
'short_description' => $category['short_description'],
|
|
]);
|
|
$categoryIds[$category['slug']] = $created->id;
|
|
}
|
|
|
|
// --- Tags -------------------------------------------------------------
|
|
$tags = [
|
|
['name' => 'React', 'slug' => 'react'],
|
|
['name' => 'Next.js', 'slug' => 'nextjs'],
|
|
['name' => 'SEO', 'slug' => 'seo'],
|
|
['name' => 'Performance', 'slug' => 'performance'],
|
|
['name' => 'Clean Code', 'slug' => 'clean-code'],
|
|
['name' => 'Laravel', 'slug' => 'laravel'],
|
|
['name' => 'Docker', 'slug' => 'docker'],
|
|
['name' => 'DevOps', 'slug' => 'devops'],
|
|
['name' => 'Career', 'slug' => 'career'],
|
|
['name' => 'TypeScript', 'slug' => 'typescript'],
|
|
['name' => 'AI Tools', 'slug' => 'ai-tools'],
|
|
['name' => 'Freelancing', 'slug' => 'freelancing'],
|
|
['name' => 'Web Design', 'slug' => 'design'],
|
|
|
|
['name' => 'Database', 'slug' => 'database'],
|
|
['name' => 'Git', 'slug' => 'git'],
|
|
['name' => 'Testing', 'slug' => 'testing'],
|
|
['name' => 'ریاکت', 'slug' => 'react-fa'],
|
|
['name' => 'نکست', 'slug' => 'nextjs-fa'],
|
|
['name' => 'سئو', 'slug' => 'seo-fa'],
|
|
['name' => 'عملکرد', 'slug' => 'performance-fa'],
|
|
['name' => 'کد تمیز', 'slug' => 'clean-code-fa'],
|
|
['name' => 'لاراول', 'slug' => 'laravel-fa'],
|
|
['name' => 'داکر', 'slug' => 'docker-fa'],
|
|
['name' => 'دواپس', 'slug' => 'devops-fa'],
|
|
['name' => 'مسیر شغلی', 'slug' => 'career-fa'],
|
|
['name' => 'تایپاسکریپت', 'slug' => 'typescript-fa'],
|
|
['name' => 'هوش مصنوعی', 'slug' => 'ai-fa'],
|
|
['name' => 'فریلنسری', 'slug' => 'freelancing-fa'],
|
|
['name' => 'طراحی وب', 'slug' => 'design-fa'],
|
|
['name' => 'پایگاه داده', 'slug' => 'database-fa'],
|
|
['name' => 'گیت', 'slug' => 'git-fa'],
|
|
['name' => 'تست', 'slug' => 'testing-fa'],
|
|
];
|
|
|
|
$tagIds = [];
|
|
foreach ($tags as $tag) {
|
|
$created = Tag::create(['name' => $tag['name'], 'slug' => $tag['slug']]);
|
|
$tagIds[$tag['slug']] = $created->id;
|
|
}
|
|
|
|
// --- Posts ------------------------------------------------------------
|
|
// Each entry: title, slug, excerpt, category slug, tags, cover keyword,
|
|
// views, likes, days-ago for published_at, body (markdown-ish text where
|
|
// "# ", "## " and "- " lines become headings and lists on the blog).
|
|
$posts = [
|
|
// =================================================================
|
|
// English posts
|
|
// =================================================================
|
|
[
|
|
'title' => 'Next.js App Router: Why Server Components Changed How I Build Websites',
|
|
'slug' => 'nextjs-app-router-server-components',
|
|
'excerpt' => 'The App Router and React Server Components are not just new APIs; they change where your code runs. Here is how they cut bundle size, simplified data fetching, and made my pages measurably faster.',
|
|
'category' => 'react-nextjs',
|
|
'tags' => ['nextjs', 'react'],
|
|
'cover' => 'Next.js App Router guide',
|
|
'views' => 3200,
|
|
'likes' => 210,
|
|
'days_ago' => 2,
|
|
'body' => <<<'TEXT'
|
|
# The Next.js App Router
|
|
## What actually changed
|
|
Moving from the Pages Router to the App Router is the biggest shift in Next.js since the framework was released. Layouts became shareable, nested loading states became the norm, and React Server Components moved most rendering work off the client.
|
|
|
|
## Where your code runs now
|
|
- Components are Server Components by default; they render on the server and send only HTML.
|
|
- A bundle never contains what a component never has to run in the browser.
|
|
- "use client" is now an explicit opt-in, not the default.
|
|
|
|
## Why data fetching got simpler
|
|
Pages used to need `getServerSideProps` or `getStaticProps` as a separate step. In the App Router you fetch directly inside a component, and Next.js deduplicates and caches requests. That removed a whole category of props-drilling bugs I used to fix.
|
|
|
|
## Measuring the result
|
|
The most visible win was bundle size. The home page of the website this blog runs on dropped roughly 180 KB of JavaScript, and the Largest Contentful Paint improved from 2.4 seconds to about 1.1 seconds on throttled mobile.
|
|
|
|
## When to keep a Client Component
|
|
- Interactive forms with optimistic updates.
|
|
- Components that listen to browser events like scroll.
|
|
- Anything using context for frequently changing state.
|
|
|
|
Server-first is a great default, but "use client" at the right boundary is still the right call. The skill is deciding where that boundary lives.
|
|
|
|
## The takeaway
|
|
Think about the server/client boundary as a performance decision, not a fashion one. Rendering on the server by default, then pushing only what genuinely needs the browser, is a pattern that scales with your product.
|
|
|
|
## Key takeaways
|
|
- Components render on the server by default, so keep use client a deliberate opt-in at the right boundary.
|
|
- Fetch data directly inside the component and let Next.js deduplicate and cache those requests.
|
|
- Measure the migration in bundle size and LCP; this blog's home page shed about 180 KB of JavaScript.
|
|
- Keep client components only for interactive forms, browser event listeners, and frequently changing context state.
|
|
- Treat the server and client split as a performance decision, not a passing fashion.
|
|
|
|
## FAQ
|
|
|
|
Q: Do I still need getServerSideProps or getStaticProps in the App Router?
|
|
A: No. In the App Router you fetch directly inside a component, and Next.js deduplicates and caches the requests for you. That removes a separate data-fetching step and a whole category of props-drilling bugs, and it keeps unnecessary JavaScript out of the page.
|
|
|
|
Q: How do I decide whether a component should be a Client Component?
|
|
A: Ask where the work should run. Reserve use client for interactive forms with optimistic updates, components that listen to browser events such as scroll, and anything using context for frequently changing state. Everything else can stay on the server.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Core Web Vitals Explained: A Practical Guide to LCP, INP, and CLS',
|
|
'slug' => 'core-web-vitals-practical-guide',
|
|
'excerpt' => 'LCP, INP and CLS are the metrics Google uses to judge real-world performance. This guide explains what each one measures and the concrete fixes that move the needle.',
|
|
'category' => 'frontend-development',
|
|
'tags' => ['performance', 'seo'],
|
|
'cover' => 'Core Web Vitals guide',
|
|
'views' => 5400,
|
|
'likes' => 480,
|
|
'days_ago' => 5,
|
|
'body' => <<<'TEXT'
|
|
# Core Web Vitals Explained: A Practical Guide to LCP, INP, and CLS
|
|
## Why these three metrics matter
|
|
Google uses Core Web Vitals as part of its page experience signal. They describe what real users experience in the field, not what a synthetic lab test reports, so improving them is genuine product work.
|
|
|
|
## Largest Contentful Paint (LCP)
|
|
LCP measures when the largest above-the-fold element finishes loading. The target is under 2.5 seconds.
|
|
- Preload the hero image and the stylesheet that affects it.
|
|
- Serve images in modern formats with sensible dimensions.
|
|
- Cut render-blocking third-party scripts from the critical path.
|
|
|
|
## Interaction to Next Paint (INP)
|
|
INP replaces First Input Delay. It measures the worst response to a user interaction, and the good limit is 200 milliseconds.
|
|
- Keep long tasks on the main thread under 50 milliseconds.
|
|
- Defer non-essential work until after the page becomes interactive.
|
|
- Debounce expensive handlers instead of running them on every event.
|
|
|
|
## Cumulative Layout Shift (CLS)
|
|
CLS rewards pages that do not jump around while loading. A score below 0.1 is good.
|
|
- Reserve space for images and embeds with explicit dimensions.
|
|
- Avoid inserting content above existing content after the request starts.
|
|
- Let fonts keep their fallback metrics to stop invisible-text reflows.
|
|
|
|
## How to verify your work
|
|
Run Lighthouse for a quick lab pass, then compare it to CrUX field data for your real traffic. Field performance is what search engines ultimately see, so an analytics tool that reports RUM metrics is worth the setup cost.
|
|
|
|
## The takeaway
|
|
Performance is not a one-time checklist. Set the targets, add the metrics to your CI, and treat every release that regresses them as a bug.
|
|
|
|
## Key takeaways
|
|
- Judge performance with field data, because Core Web Vitals describe what real users experience, not lab results.
|
|
- Preload the hero image and its stylesheet, then move render-blocking third-party scripts out of the critical path.
|
|
- Keep main-thread long tasks under 50 milliseconds and debounce expensive handlers to protect the 200 millisecond INP limit.
|
|
- Reserve explicit space for images and embeds so nothing shifts and CLS stays below 0.1.
|
|
- Add the metrics to CI and treat any release that regresses them as a bug, not a follow-up ticket.
|
|
|
|
## FAQ
|
|
|
|
Q: Which is better for checking my work, Lighthouse or CrUX?
|
|
A: Use both, for different jobs. Lighthouse gives a quick lab pass you can run on every change, while CrUX field data shows what your real traffic experienced. Search engines ultimately judge field performance, so a tool that reports RUM metrics is worth the setup cost.
|
|
|
|
Q: Why is my CLS worse than my LCP after a redesign?
|
|
A: Most layout shift comes from content arriving without reserved space. Give images and embeds explicit dimensions, avoid inserting anything above content that already exists, and let fonts keep their fallback metrics so text does not reflow when the real font arrives.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Building Robust RESTful APIs with Laravel: Validation, Resources, and Rate Limiting',
|
|
'slug' => 'laravel-api-validation-resources-throttling',
|
|
'excerpt' => 'The pieces that keep a Laravel API clean and safe: form requests for validation, API resources for a consistent response shape, and throttling to protect public endpoints.',
|
|
'category' => 'backend-development',
|
|
'tags' => ['laravel', 'clean-code'],
|
|
'cover' => 'Laravel REST API guide',
|
|
'views' => 1800,
|
|
'likes' => 150,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# Building Robust RESTful APIs with Laravel
|
|
## Start with the shape of your responses
|
|
The fastest way to make an API pleasant to consume is a stable response shape. Laravel's API resources give you a single place to define it, so the frontend never has to guess whether a payload is an object, an array, or something in between.
|
|
|
|
## Validation belongs in Form Requests
|
|
Writing rules inside the controller works, but it stops scaling. Extract them into a Form Request so that validation, authorisation and rules live next to each other and can be tested in isolation.
|
|
- Keep rules close to the domain they describe.
|
|
- Return the default 422 error shape; most clients already parse it.
|
|
- Add a couple of custom rules for the weird cases instead of piling conditions into the controller.
|
|
|
|
## Rate limiting is a safety feature, not a niche
|
|
A public write endpoint is a spam magnet until you throttle it. Prefix the route with a reasonable throttle such as a few attempts per minute, and watch what legitimate clients actually need before tuning.
|
|
- Use named limiters so the rules are easy to read.
|
|
- Return a 429 with the `Retry-After` header.
|
|
- Remember that a public contact form needs more protection than an authenticated admin route.
|
|
|
|
## What this website uses
|
|
The blog and website APIs follow exactly this pattern: form requests for validation, JSON resources for output, and per-route throttles so anonymous traffic cannot flood the database.
|
|
|
|
## The takeaway
|
|
Small, boring conventions beat clever abstractions. A consistent response shape, centralised validation and sensible throttling will take an API from "works for me" to "works for everyone".
|
|
|
|
## Key takeaways
|
|
- Define the response shape once with API resources so clients never guess whether a payload is an object or an array.
|
|
- Move validation, authorisation and rules into Form Requests so they live together and can be tested in isolation.
|
|
- Return the default 422 error shape, since most clients already know how to parse it.
|
|
- Throttle every public write route, then tune the number from what legitimate clients actually need.
|
|
- Remember a public contact form needs far more protection than an authenticated admin route.
|
|
|
|
## FAQ
|
|
|
|
Q: Why move validation out of the controller into a Form Request?
|
|
A: Rules inside a controller work until they stop scaling. A Form Request keeps validation, authorisation and rules next to each other, lets you test them in isolation, and keeps the rules close to the domain they describe.
|
|
|
|
Q: How do I choose a sensible rate limit for a public endpoint?
|
|
A: Start with something reasonable, such as a few attempts per minute, and watch what legitimate clients actually need before tuning it. A public contact form deserves more protection than an authenticated admin route, because anonymous traffic can flood the database.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Zero-Downtime Deployments with Docker Compose: A Step-by-Step Guide',
|
|
'slug' => 'zero-downtime-deployments-docker-compose',
|
|
'excerpt' => 'Rolling updates, health checks and the careful order of flags — how to update a Docker Compose stack without dropping a single request.',
|
|
'category' => 'devops-deployment',
|
|
'tags' => ['docker', 'devops'],
|
|
'cover' => 'Docker Compose deploy',
|
|
'views' => 2600,
|
|
'likes' => 230,
|
|
'days_ago' => 14,
|
|
'body' => <<<'TEXT'
|
|
# Zero-Downtime Deployments with Docker Compose
|
|
## The goal
|
|
A restart that takes your site offline for a few seconds is a deployment that failed quietly. With a reverse proxy in front and a health check after it, a Compose stack can be updated while the old container keeps serving traffic.
|
|
|
|
## Health checks come first
|
|
Compose lets you declare a healthcheck for every service.
|
|
- The proxy should only pass traffic to containers reporting "healthy".
|
|
- The application's health endpoint must not just return 200; it should verify the database connection behind it.
|
|
- Give the check a generous start period on the first boot.
|
|
|
|
## The update strategy
|
|
When you run `docker compose up -d`, Compose recreates changed containers one by one. Pair that with a running proxy and you get a rolling update for free.
|
|
- Run the migrations and other long tasks as a separate one-shot service before the web container restarts.
|
|
- Let the new container reach healthy before the old one is removed.
|
|
- Watch the logs during the switch instead of walking away.
|
|
|
|
## What this blog's deploy actually does
|
|
The deploy script for this site pulls the new images, runs a migration guard, starts the new containers and then verifies a health URL returns 200 before reporting success. That verification step is what turns a deploy from a wish into a fact.
|
|
|
|
## The takeaway
|
|
Zero downtime is a composition of small habits: a real health endpoint, a proxy that respects it, and a deploy script that will not celebrate early. Automate the checks and your teammates will thank you.
|
|
|
|
## Key takeaways
|
|
- Put a reverse proxy in front of the stack and let it forward traffic only to containers reporting healthy.
|
|
- Make the health endpoint check the database connection, not just return a 200 status code.
|
|
- Run migrations as a separate one-shot service so they finish before the web container restarts.
|
|
- Give the first boot a generous health-check start period so slow starts are not killed.
|
|
- Verify a health URL returns 200 before the deploy script reports success, and watch the logs during the switch.
|
|
|
|
## FAQ
|
|
|
|
Q: What actually makes a Docker Compose update zero-downtime?
|
|
A: The combination of a reverse proxy and a real health check. Compose recreates changed containers one by one, so as long as the proxy forwards traffic only to healthy containers, the old container keeps serving while the new one boots.
|
|
|
|
Q: What should a health endpoint check before I call a deploy successful?
|
|
A: More than a status code. The endpoint should verify the database connection behind it, and the deploy script should fetch a health URL and see 200 before it reports success. That verification step is what turns a deploy from a wish into a fact.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'How I Interview Frontend Developers: 8 Questions That Predict Real Performance',
|
|
'slug' => 'frontend-interview-questions',
|
|
'excerpt' => 'The questions I actually ask in frontend interviews, and what I am listening for in each answer — from layout behaviour to how a candidate handles a broken build.',
|
|
'category' => 'programming-careers',
|
|
'tags' => ['react', 'clean-code', 'career'],
|
|
'cover' => 'Frontend interview questions',
|
|
'views' => 4100,
|
|
'likes' => 390,
|
|
'days_ago' => 21,
|
|
'body' => <<<'TEXT'
|
|
# How I Interview Frontend Developers
|
|
## Why I stopped asking trivia
|
|
Reciting a list of hook names tells me a candidate can memorize; it tells me nothing about how they will behave on Monday morning. I measure judgement, debugging skill and the ability to explain trade-offs.
|
|
|
|
## The questions
|
|
- What happens between the URL and the first paint?
|
|
- When would you reach for `useEffect` to load data, and why is that usually the wrong default?
|
|
- A component re-renders every keystroke. Where do you start looking?
|
|
- Describe a layout problem you solved with `position: absolute`. When was it a mistake?
|
|
- How would you migrate a legacy class component without breaking the app?
|
|
- Your `npm ci` fails on the CI server but works locally. What do you check?
|
|
- Explain the difference between `LCP` and `TTFB` to a product manager.
|
|
- When was the last time you shipped something you were embarrassed about?
|
|
|
|
## What I listen for
|
|
- Naming the actual browser steps beats quoting docs.
|
|
- A candidate who says "it depends" and then names the dependence is my favourite kind of engineer.
|
|
- Debugging confidence matters more than a perfect first answer. I want to hear how they think, not whether they guessed right.
|
|
|
|
## The takeaway
|
|
Interviews should simulate the job: trade-offs, debugging and clear communication. Questions that reward those skills find engineers who actually ship.
|
|
|
|
## Key takeaways
|
|
- Drop trivia questions and measure judgement, debugging skill and the ability to explain trade-offs instead.
|
|
- Ask questions that mirror the job, from what happens between the URL and first paint to a failing npm ci.
|
|
- Reward candidates who name real browser steps over those who quote documentation back at you.
|
|
- Treat an honest it depends, followed by naming the dependence, as a strong signal.
|
|
- Value debugging confidence and visible reasoning more than a perfect first answer.
|
|
|
|
## FAQ
|
|
|
|
Q: Why stop asking questions like which hooks exist?
|
|
A: Reciting hook names only shows someone can memorise, and it says nothing about how they behave on Monday morning. The questions that matter measure judgement, debugging skill and the ability to explain trade-offs, which is what the job actually demands.
|
|
|
|
Q: What does a strong answer look like when a candidate is stuck?
|
|
A: I want to hear how they think, not whether they guessed right. Naming the actual browser steps beats quoting docs, and a candidate who says it depends and then names the dependence is my favourite kind of engineer.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'React Server Components vs. Client Components: When to Use Each',
|
|
'slug' => 'react-server-vs-client-components',
|
|
'excerpt' => 'The mental model behind the server/client boundary in modern React, with concrete examples of what belongs on each side — and what the next.js app router actually compiles.',
|
|
'category' => 'react-nextjs',
|
|
'tags' => ['react', 'nextjs'],
|
|
'cover' => 'React Server Components',
|
|
'views' => 2900,
|
|
'likes' => 270,
|
|
'days_ago' => 30,
|
|
'body' => <<<'TEXT'
|
|
# React Server Components vs. Client Components
|
|
## The one sentence mental model
|
|
A Server Component renders where your data lives; a Client Component renders where your user lives. Everything else follows from that sentence.
|
|
|
|
## What Server Components give you
|
|
- Direct access to the database and filesystem without an extra API call.
|
|
- Zero runtime JavaScript for the parts that only display content.
|
|
- Smaller bundles, because libraries used on the server never reach the browser.
|
|
|
|
## What forces a Client Component
|
|
- State and effects: `useState`, `useEffect`, event handlers.
|
|
- Browser APIs: geometry, media queries, storage.
|
|
- Context and interactivity that users feel immediately.
|
|
|
|
## The tricky middle
|
|
Props passed from a server component become serialized data, so surprises hide in the boundary.
|
|
- Functions and class instances do not survive the boundary.
|
|
- Keep client components close to the interaction leaves, and push server components up toward the data roots.
|
|
- When a component "is both", split it: a client wrapper with a server body.
|
|
|
|
## How this blog is organised
|
|
Pages and post bodies are server-rendered, while the theme toggle and the mobile menu are client islands. That split is why the site stays interactive while shipping a very small amount of JavaScript.
|
|
|
|
## The takeaway
|
|
Stop thinking "this component can use hooks, therefore client". Ask where the work should run, then let the framework handle the rest.
|
|
|
|
## Key takeaways
|
|
- Ask where the work should run: server components render where the data lives, client components where the user is.
|
|
- Keep interactive leaves as client components and push server components up toward the data roots.
|
|
- Remember props crossing the boundary become serialized data, so functions and class instances never survive it.
|
|
- Split a component that is both into a client wrapper and a server body instead of guessing at the boundary.
|
|
- Give display-only sections to the server so you ship zero runtime JavaScript for them.
|
|
|
|
## FAQ
|
|
|
|
Q: What makes a component a Client Component?
|
|
A: Not the ability to use hooks, but the work it needs to do. State, effects, event handlers, browser APIs like geometry, media queries and storage, and interactivity users feel immediately are what force a component to be client.
|
|
|
|
Q: What breaks when I pass props from a Server Component to a Client Component?
|
|
A: Props crossing that boundary become serialized data, and functions and class instances do not survive it, so surprises hide there. Keep client components near the interaction leaves and push server components up toward the data roots.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'Technical SEO and Core Web Vitals for Persian websites',
|
|
'slug' => 'technical-seo-persian-websites',
|
|
'excerpt' => 'Persian WordPress sites suffer from predictable Core Web Vitals problems — oversized Vazirmatn fonts, unoptimized hero images, and RTL layout bugs. Here is the fix list I actually ship.',
|
|
'category' => 'web-performance-seo',
|
|
'tags' => ['seo', 'performance'],
|
|
'cover' => 'Core Web Vitals checklist for Persian websites',
|
|
'views' => 1900,
|
|
'likes' => 130,
|
|
'days_ago' => 11,
|
|
'body' => <<<'TEXT'
|
|
# Technical SEO and Core Web Vitals for Persian websites
|
|
|
|
Every few weeks I get a message that goes roughly like this: "My Persian site is beautiful, I rank for my keywords, but traffic is flat and Search Console says my pages are not good for users." Then they attach a PageSpeed report. Almost every time, the numbers are bad in the same three places: LCP, INP, and CLS, and the causes are the same too: a heavyweight WordPress theme stacked with plugins, Persian webfonts loaded like a multi-megabyte download, and hero images uploaded untouched.
|
|
|
|
This is not a rare condition. It is the default state of much of the Iranian web, and one competent developer can turn it around in a week.
|
|
|
|
## Why Persian sites score badly, in practice
|
|
|
|
The typical case: a WordPress install running a Persianized theme, plus a page builder, a font plugin, a slider, social widgets, a chat widget, and an analytics snippet copied from a global tutorial. That is forty to seventy requests and three to five megabytes of transfer. On the mobile connections most Iranian visitors actually have, LCP lands between four and eight seconds.
|
|
|
|
Fonts are the most common culprit, and they are uniquely bad for Persian. Latin fonts ship small glyph subsets and the browser drops unused weights. Persian script carries larger connected glyph sets, and families like Vazirmatn, Estedad, or Sahel include many weights. A theme loading six weights as separate files ships far more glyph data than any page needs.
|
|
|
|
## The RTL dimension most guides skip
|
|
|
|
RTL is not just setting direction on the body. Line metrics, text rendering, and layout stability all change.
|
|
|
|
Persian text is taller than Latin at the same font-size because of descenders, diacritics, and ZWNJ. Many Latin-derived CSS resets under-size line-height for Persian, so lines clip or overlap, and fixing that later shifts the layout, which makes CLS worse rather than better. Test with real strings containing ک, گ, ی and Persian digits ۰۱۲۳, never placeholders.
|
|
|
|
Bidirectional text is the other trap. A page with embedded English product names, mixed currency prices, or code snippets will show flipped parentheses and misplaced punctuation if isolated left-to-right runs are not handled. No automated test flags that.
|
|
|
|
## What Google actually does with fa pages
|
|
|
|
Google Discover behaves differently in this market, and it comes up on nearly every client call. It leans hard on structured data and visually rich feeds, and its availability and click-through rate inside Iran is not comparable to organic search. Discover-first strategies that work for large international brands do not transfer cleanly.
|
|
|
|
So prioritize being fast, crawlable, and indexable, then add Article, BreadcrumbList, and Organization schema where it is genuinely accurate rather than treating Discover as the plan.
|
|
|
|
## Fonts: the highest-leverage fix
|
|
|
|
Stop loading a font family. Load one family, two weights maximum, and only the weights visible above the fold.
|
|
|
|
Preload the primary woff2 file so the browser starts fetching before it finishes parsing CSS, and subset to Persian plus Latin digits where you can. Set `font-display` deliberately, because the common values behave very differently. `swap` creates an invisible-text window where fallback Latin metrics render and the Persian text then reflows into place, a direct CLS contributor. `optional` avoids that reflow, but a visitor on a cold cache may see the fallback. For a Persian content site where the typeface carries brand value, I usually test `optional` with a tight preload and let field data decide.
|
|
|
|
## Images and the LCP element
|
|
|
|
On most Persian sites the LCP element is the hero image or the logo. Compress it, serve AVIF with a WebP fallback, size it to the largest layout slot, and declare explicit `width` and `height` so the browser reserves space before paint. Lazy-load everything below the fold, and never the LCP candidate, which is the most common self-inflicted regression I see.
|
|
|
|
## Hosting and network reality in Iran
|
|
|
|
This is where a Western checklist stops being directly usable. Iranian visitors frequently hit high latency and packet loss toward European and North American origins, and access to some CDNs is inconsistent. A Cloudflare-fronted site can be excellent in Frankfurt and mediocre in Tehran, so judge any acceleration decision from real-user data inside Iran.
|
|
|
|
My default: host in Iran if your audience is entirely domestic, or in a nearby region such as Istanbul or the Gulf with a CDN in front and aggressive caching. Never cache HTML for more than a few minutes, cache static assets for a year behind versioned URLs, and compress text with Brotli.
|
|
|
|
## The practical checklist
|
|
|
|
- Cut plugins to only what earns its place; every script is a dependency you do not control.
|
|
- Load one Persian font family, two weights, subset and preloaded.
|
|
- Give every image explicit dimensions, use AVIF, never lazy-load the LCP image.
|
|
- Verify line-height and baseline with real Persian strings.
|
|
- Choose `font-display` on purpose and confirm with field CLS.
|
|
- Brotli the text, long-cache static assets, short-cache HTML.
|
|
- Review mixed Persian and Latin pages by eye for bidi problems.
|
|
- Add structured data only where it reflects the real page.
|
|
- Compare before and after with real-user monitoring segmented by country.
|
|
|
|
Core Web Vitals are not mysterious, and for a Persian site they are rarely about cleverness. They are about removing weight, choosing fewer font weights, and measuring from where your users actually are.
|
|
|
|
## Key takeaways
|
|
- Load one Persian font family, two weights maximum, subset and preloaded. It is the highest-leverage fix available.
|
|
- Never lazy-load the LCP candidate. Compress it, serve AVIF with a WebP fallback, and declare explicit width and height.
|
|
- Verify line-height and layout with real Persian strings, including ZWNJ and Persian digits, not English placeholders.
|
|
- Judge hosting and CDN choices from real-user data inside Iran, because a site can be excellent in Frankfurt and mediocre in Tehran.
|
|
- Prioritize being fast, crawlable and indexable first, then add structured data only where it is genuinely accurate.
|
|
|
|
## FAQ
|
|
|
|
Q: My Persian site ranks fine but traffic is flat. Where do I start?
|
|
A: The same three numbers fail almost every time: LCP, INP and CLS. The causes are a heavyweight theme stacked with plugins, Persian webfonts loaded as multiple weights, and untouched hero images.
|
|
|
|
Q: Should I use font-display swap or optional?
|
|
A: swap renders fallback Latin metrics first, then reflows Persian text, which directly causes CLS. optional avoids that reflow but a cold-cache visitor may see the fallback, so I test optional with a tight preload and let field CLS decide.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Freelancing and remote work for developers in Iran: a practical field guide',
|
|
'slug' => 'iranian-developers-freelancing-remote',
|
|
'excerpt' => 'Rates are not the lever. Public evidence, payment rails that survive Iranian residency, tight scopes, and scam avoidance are — a practical field guide to sustainable remote income.',
|
|
'category' => 'programming-careers',
|
|
'tags' => ['freelancing', 'career'],
|
|
'cover' => 'Remote freelancing playbook for Iranian developers',
|
|
'views' => 2200,
|
|
'likes' => 160,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# Freelancing and remote work for developers in Iran: a practical field guide
|
|
|
|
I have hired Iranian developers, worked alongside them as a contractor, and mentored juniors in Tehran and Shiraz. This is what separates the ones who build durable international income from the ones stuck bidding for the same three-line feature.
|
|
|
|
## Position on outcomes, not on hours
|
|
|
|
The biggest shift in my own career was from selling hours to selling results. A developer who says "I build dashboards, twenty-five dollars an hour" competes with the entire global supply of developers at the bottom of the market. The same developer who says "I rebuilt your analytics pipeline and reporting dropped from two days to twenty minutes" competes with almost nobody.
|
|
|
|
Pick one or two problems you can measurably improve: load time, conversion, churn, deploy frequency, infrastructure cost, pipeline latency. Write about them with numbers attached. Evidence beats a rate card every time.
|
|
|
|
## Build a portfolio that works while you sleep
|
|
|
|
Three things, in order of weight.
|
|
|
|
Deployed projects people can click. A working product beats a screenshot of one. If you cannot deploy for a client, deploy for yourself and let strangers use it.
|
|
|
|
A technical blog. I have received inbound offers specifically because of posts I wrote years earlier. Write about problems you solved, including the trade-offs and the mistakes. A blog is proof of how you think.
|
|
|
|
A clean, active GitHub. Readable history, sensible issues, small focused pull requests, an honest README. Buyers do not test your skills in a call. They check whether you look like someone who would embarrass them, and public work does that screening for free.
|
|
|
|
## Landing the first foreign client
|
|
|
|
Nobody discovers a brand-new freelancer, so go where the work is described, and go narrow.
|
|
|
|
Cold outreach works when it is specific: I read your pricing page, here is the one thing that looks wrong, here is what I would change, here is comparable work. Follow up twice, then stop.
|
|
|
|
Communities beat cold mail. Technical forums, maintainers who need help, indie hacker circles, and small agencies who subcontract overflow. Agencies in particular, because a reliable subcontractor gets repeat work.
|
|
|
|
Domestic platforms such as ParsiFox are fine for the first invoice, which is always the hardest.
|
|
|
|
## Money: the part most advice skips
|
|
|
|
Let me be blunt. For an Iranian contractor, getting paid is harder than doing the work, and you should solve this before you sign anything.
|
|
|
|
Establish what is legally available where you live. Escrow providers, international processors, and banking relationships that accept Iranian residents are real options, but availability, fees, and compliance requirements shift. Read the current terms, and if the sums justify it, get professional advice on your tax position.
|
|
|
|
Cryptocurrency has become the default settlement path many Iranian freelancers use, precisely because it avoids banking friction. It also brings volatility, irreversible-transfer risk, counterparty risk, and regulatory ambiguity. I use it. I do not romanticize it. Convert earnings into something stable to hold, and never accept "trust me, the transfer is on its way."
|
|
|
|
Two habits have saved me money more than once: always use escrow or milestones, and never start without a written scope and a deposit.
|
|
|
|
## Contracts, scope, and timezones
|
|
|
|
A short written agreement protects both sides. It needs a defined deliverable, a number of revision rounds, payment terms and currency, IP ownership and when it transfers, a kill fee, and a dispute path. One page is enough.
|
|
|
|
Scope creep is not client evil, it is undefined work. When a request falls outside the agreed deliverable, I quote it separately with its own timeline. That habit roughly doubled my effective rate without raising my price.
|
|
|
|
Iran is UTC+3:30, far more workable than people assume. You overlap comfortably with European morning hours, the Gulf, India, and South-East Asia. US East Coast is reachable in early evening Iranian time. US West Coast means midnight, which is why I stopped taking those clients years ago. Choose niches where your hours are an advantage: overnight deployments, asynchronous review, follow-the-sun work.
|
|
|
|
## Avoiding scams and reading the domestic market
|
|
|
|
The scam red flags are consistent: a vague project, an implausibly generous budget, refusal of any video call, a demand to pay money upfront to "unlock the platform," or an offer to pay you to receive and forward funds. That last one is money laundering. Verify identity first, break work into small milestones, keep every instruction in writing, and never send funds to an address dictated over a voice call.
|
|
|
|
Iranian freelance work pays a fraction of international rates. It is also low-friction and produces references you can use immediately. The problem is that many domestic projects are priced by feature count with no maintenance budget behind them, which is how you support one codebase for years.
|
|
|
|
For juniors I advise taking two or three domestic projects to build a portfolio, then steering toward clients who value what you do rather than winning the cheapest bid. The learning curve is identical, the compounding is not.
|
|
|
|
## What actually compounds
|
|
|
|
Rates plateau early unless you move toward higher-leverage work: architecture, performance, data, security, or part ownership of a product. Every year, either your scope gets wider or your number gets smaller.
|
|
|
|
The developers doing well did not work the most hours. They made one thing public, wrote about it honestly, and let that compound while they started the next thing.
|
|
|
|
## Key takeaways
|
|
- Sell outcomes with numbers attached. An hourly rate puts you at the bottom of the global supply of developers.
|
|
- Build three proof assets in order: a deployed project people can click, a technical blog, and a clean GitHub.
|
|
- Quote anything outside the agreed deliverable separately. That habit roughly doubled my effective rate without a price rise.
|
|
- Never start without a written scope and a deposit, and solve the payment route before you sign anything.
|
|
- Write technical English well. For foreign teams documentation is part of the job, not an interruption.
|
|
|
|
## FAQ
|
|
|
|
Q: What to fix first when starting to freelance from Iran?
|
|
A: Position on outcomes rather than hours, then build a portfolio that works while you sleep: a deployed project, a technical blog, a clean GitHub.
|
|
|
|
Q: Is cryptocurrency a safe way to get paid?
|
|
A: It has become the default settlement path many Iranian freelancers use because it avoids banking friction, and I use it without romanticizing it. It also carries volatility, counterparty risk and regulatory ambiguity, so convert earnings into something stable.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'AI and the future of programming jobs for developers in Iran',
|
|
'slug' => 'ai-coding-careers-iran',
|
|
'excerpt' => 'An honest 2026 look at which AI skills keep Iranian developers relevant, what genuinely stays human, and why falling six months behind matters more than any model.',
|
|
'category' => 'programming-careers',
|
|
'tags' => ['ai-tools', 'career'],
|
|
'cover' => 'Staying relevant when AI writes boilerplate',
|
|
'views' => 2000,
|
|
'likes' => 145,
|
|
'days_ago' => 6,
|
|
'body' => <<<'TEXT'
|
|
# AI and the future of programming jobs for developers in Iran
|
|
|
|
I have hired and mentored plenty of developers, so when someone asks whether AI is coming for their job, I answer from daily use rather than from a conference stage. I use it for refactors and gnarly bug hunts, for the tedious half of a form, and for generating five layout variants in thirty seconds.
|
|
|
|
## What AI genuinely automates well
|
|
|
|
Boilerplate and scaffolding. A CRUD layer, a typed API client, a component with props and tests, a migration. That was already low-value work I was mildly embarrassed by. Now it is nearly free, and I am glad about it.
|
|
|
|
Retrieval-shaped work: finding the right file in an unfamiliar codebase, tracing where a value comes from, explaining a tangled module. And the first draft of tests, types, and documentation.
|
|
|
|
## What it does not touch
|
|
|
|
Requirements are still hard. Knowing what to build, and more importantly what to refuse, comes from talking to users and understanding how a business makes money. I have watched AI implement a feature nobody wanted, beautifully and quickly, and it was worth nothing.
|
|
|
|
Debugging in production is not writing the code that throws. It is instrumenting, reading logs, forming a hypothesis, and deciding which of ten plausible causes is the real one. That is slower than generation and far more valuable.
|
|
|
|
Architecture is accountability. Where does state live, what is the migration path, how do we roll back at two in the morning, who explains the trade-off six months from now. A model can propose an answer; a human signs it.
|
|
|
|
Code review has changed rather than shrunk. There is more generated code, so the work shifts to verifying whether it is correct, idiomatic, secure, and consistent with its surroundings. That skill pays more than writing it.
|
|
|
|
I have also noticed AI is weakest exactly where Iranian developers often work: legacy PHP and WordPress codebases, integrations with local payment gateways, systems with no tests and no docs. It guesses with total confidence, and you have to read everything.
|
|
|
|
## The part that actually decides your income
|
|
|
|
Here is my honest 2026 assessment. The floor of this market is falling fast; routine implementation work is priced lower every quarter. The ceiling is not moving.
|
|
|
|
For an Iranian developer specifically, the constraint is not that your coding is worse. The developers I work with are excellent. The constraint is access: to the market, to the English discourse where fast knowledge lives, and to the organizations that pay international rates.
|
|
|
|
So the leverage is English plus fundamentals plus shipping, not English plus AI tooling. These tools compress the gap between a beginner and a competent developer on a well-specified task. They do not close the gap between someone who understands the domain and someone who does not.
|
|
|
|
## How to position now
|
|
|
|
- Move toward work where AI output needs human judgment: product sense, debugging, performance, security, data modelling, architecture review.
|
|
- Learn to review generated code as your core competency. Prompting is table stakes; verification is the job.
|
|
- Own the whole slice: problem, design, build, deploy, measure, maintain. Someone accountable for outcomes is not a code generator.
|
|
- Write in English. Technical writing is both a learning mechanism and my best inbound lead source.
|
|
- Learn infrastructure: Linux, Docker, CI, databases, observability. That is what separates a senior from a fast junior.
|
|
|
|
## Advice for juniors in Iran
|
|
|
|
The junior pipeline is where I have the most concern and the most hope. Bad advice: learn a framework, ship nothing, wait for a job. Frameworks were always the part that got automated.
|
|
|
|
Better advice. Spend your first year on fundamentals: data structures, networking, databases, operating systems, and reading other people's code. AI cannot teach you taste because it has none. Ship small real things immediately, because a tool your family uses beats a portfolio of tutorial clones. Learn English by consuming technical English: docs, source, issue threads.
|
|
|
|
Use AI as a pair, but attempt it yourself first. If you ask for the solution immediately, you are training yourself to be the person who cannot work without autocomplete, which is the job being automated. And get your code reviewed by someone better than you.
|
|
|
|
## The real threat
|
|
|
|
AI is not the threat to Iranian developers. Being six months behind is.
|
|
|
|
The developers I worry about are not the ones whose jobs vanish next year. They are the ones who spent two years waiting to see whether all of this was really going to matter, and are now finding that the baseline of what a junior must deliver moved up.
|
|
|
|
The developers I do not worry about are the ones shipping publicly, in English, with AI in the loop, and accountable for what they ship.
|
|
|
|
## Where I land
|
|
|
|
AI makes the first eighty percent of many tasks much cheaper and faster, and sharply raises the value of the last twenty percent. Jobs do not disappear, but their shape changes: fewer people maintaining large volumes of hand-written code, more people owning systems and outcomes.
|
|
|
|
If you are in Iran and worried, do not compete with the model on volume. Become the engineer whose judgment is hard to fake and whose work is easy for anyone to evaluate.
|
|
|
|
I have never seen a shortage of clients for that person. I have seen a shortage of them everywhere.
|
|
|
|
## Key takeaways
|
|
- Treat reviewing generated code as the core competency. Prompting is table stakes, verification is the job.
|
|
- Move toward work where AI output needs human judgment: product sense, debugging, performance, security, architecture.
|
|
- Learn infrastructure, Linux, Docker, CI, databases and observability. That is what separates a senior from a fast junior.
|
|
- Write in English. Technical writing is both a learning mechanism and my best source of inbound leads.
|
|
- Do not compete with the model on volume. Own the whole slice from problem to deploy to measurement.
|
|
|
|
## FAQ
|
|
|
|
Q: Will AI take my programming job?
|
|
A: The floor of this market is falling fast while the ceiling is not moving, because routine implementation work is priced lower every quarter. Jobs do not vanish, but fewer people maintain hand-written code and more own outcomes.
|
|
|
|
Q: Where should a junior in Iran start?
|
|
A: Not with a framework, shipping nothing and waiting for a job, because frameworks were always the part that got automated. Spend your first year on fundamentals, ship small real things immediately, and use AI as a pair after attempting it yourself.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Web design for Iranian small businesses: what actually works',
|
|
'slug' => 'web-design-iranian-businesses',
|
|
'excerpt' => 'What I have learned rebuilding business websites in Iran: a fast, trustworthy RTL site that sells, instead of a pretty brochure nobody can load on mobile.',
|
|
'category' => 'frontend-development',
|
|
'tags' => ['design', 'performance'],
|
|
'cover' => 'A fast, trustworthy RTL website for Iranian small businesses',
|
|
'views' => 1800,
|
|
'likes' => 125,
|
|
'days_ago' => 14,
|
|
'body' => <<<'TEXT'
|
|
# Web design for Iranian small businesses: what actually works
|
|
|
|
Most small business websites in Iran are built by whoever happened to be free last week, on a template from a marketplace, and then never touched again. I have audited enough of them to say the pattern is consistent: the owner wants more customers, and the site delivers a slideshow. Here is what I have seen actually work when I rebuild these, and what I deliberately leave out.
|
|
|
|
## What almost every one of them gets wrong
|
|
|
|
- The brochure site. A hero image, an about paragraph written in 2017, a contact form nobody monitors, and no way to buy, book, or reserve anything. It exists for decoration and for printing on a business card.
|
|
- The hero carousel. Three to five rotating banners, crossfading every four seconds, each with an oversized Persian headline and a drop shadow. On a mid-range Android phone this is the main reason the page feels slow, and nobody waits.
|
|
- Font bloat. Loading Vazirmatn, Estedad, Samim, IRANSans and a Persian numeral font, each in multiple weights, all at once. Persian webfonts are large, and mobile data on Iranian plans is not unlimited the way people assume.
|
|
- Desktop first. Designed at 1440px and then squeezed. The navigation collapses into a broken hamburger and the phone number ends up in a tiny footer nobody taps.
|
|
- No trust signals. An unofficial logo, no address, no licence, no reviews.
|
|
|
|
## What these sites actually need
|
|
|
|
Start with a clear mobile first RTL layout. Most traffic is Android on a mid-range device, arriving from an Instagram bio or a Telegram channel. So: right aligned text, `dir="rtl"` on the document, a sticky bottom bar with call and WhatsApp buttons, and exactly one obvious action per screen. Reading order should match how Persian text is actually scanned.
|
|
|
|
Persian typography without bloat is simpler than people assume. One variable font file, two or three weights, `font-display: swap`, self hosted, nothing else. Body text at 16 to 17px with line height near 1.9, because Persian needs more vertical space than Latin. Keep prices in Latin digits so people can compare them, but format dates and phones the way your customers expect.
|
|
|
|
Speed is a trust signal here. My target is LCP under 2.5 seconds, ideally under 1.8, measured on a throttled Iranian mobile connection where latency is often 60 to 120ms even on a fast plan. That means one properly sized hero image in AVIF or WebP with explicit dimensions, no render blocking CSS, no carousel library, and lazy loading below the fold.
|
|
|
|
Trust elements are what convert, and they are boring: your real street address with a map embed, your business licence and the enamad (نماد اعتماد) badge if you have one, a phone number a human answers, WhatsApp with a pre-filled message, opening hours including that the Iranian week runs Saturday to Thursday, and real testimonials with names and dates. For maps use Neshan or Mapir embeds, because Google is filtered on most Iranian networks, and keep the address as plain text so it can be copied into any app.
|
|
|
|
## Commerce that converts on Iranian phones
|
|
|
|
Most of these businesses need a catalog, not a checkout platform. A grid of products or services, each with one photo, a price, and a WhatsApp button that opens a message with the product name already written. That converts better than a cart, because the buyer finishes the order inside the app they already use.
|
|
|
|
If customers are on limited plans, prepaid data, or weak WiFi, say call to reserve instead of shipping a booking flow. Fewer plans means fewer decisions.
|
|
|
|
## The rebuild checklist
|
|
|
|
- Crawl the current site and record traffic, top landing pages, and every indexed URL before changing anything.
|
|
- Keep every URL that has traffic and 301 the rest to the closest equivalent.
|
|
- Cut the carousel, the sliders, and every plugin whose only job is animation.
|
|
- Consolidate to one self hosted variable Persian font.
|
|
- Rebuild the hero as a single real photo or product shot, not a designed graphic.
|
|
- Add the trust block: address, map, licence, phone, WhatsApp, hours, reviews.
|
|
- Replace the contact form with a real inbox plus the WhatsApp button.
|
|
- Compress every image and add width and height attributes.
|
|
- Run Lighthouse on a mobile profile and aim for 90 plus on performance, accessibility, and SEO.
|
|
- Set up Search Console with a clean sitemap, or a first party analytics tool.
|
|
|
|
## What it costs
|
|
|
|
A marketplace template theme runs a few million Toman, and you will spend more fixing it than you saved. A well built custom Next.js or static site for a small business lands roughly 15 to 45 million Toman, depending on page count, whether there is a catalog, and whether the owner gets a headless CMS to edit content. Hosting and care sit on top as a small monthly figure. Treat the Toman number as the anchor, since exchange rates move and comparisons across currencies mislead.
|
|
|
|
## The point
|
|
|
|
A small business site does not need to impress designers. It needs to load in a few seconds on a cheap phone, say exactly what the business sells and how to reach it, and look like a real business with a real address. Everything else is decoration.
|
|
|
|
## Key takeaways
|
|
- Design mobile first and right to left, because most traffic arrives from an Instagram bio or a Telegram channel.
|
|
- Cut the hero carousel, the extra font families, and every plugin whose only job is animation.
|
|
- Trust is what converts: real address, map, business licence, enamad badge, an answered phone, real reviews.
|
|
- Sell through a catalog grid with a WhatsApp button, not a full checkout platform, because buyers finish inside the app they use.
|
|
- Target LCP under 2.5 seconds, ideally under 1.8, on a throttled Iranian mobile connection.
|
|
|
|
## FAQ
|
|
|
|
Q: What does a small business website in Iran actually need?
|
|
A: It must load in a few seconds on a cheap phone, say what the business sells and how to reach it, and look like a real business with a real address. Impressing designers is not the goal.
|
|
|
|
Q: Should I build a cart or a booking flow?
|
|
A: Most need a catalog, not a checkout platform: one photo, a price, and a WhatsApp button with a pre-filled message. That converts better because the buyer finishes the order inside the app they already use.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'The React job market in Iran: full-time employment or freelance',
|
|
'slug' => 'react-nextjs-job-market-iran',
|
|
'excerpt' => 'How Iranian React and Next.js developers should choose between a salaried job and independent work in 2026, including what the market actually pays.',
|
|
'category' => 'programming-careers',
|
|
'tags' => ['react', 'nextjs', 'career'],
|
|
'cover' => 'React and Next.js careers in Iran in 2026',
|
|
'views' => 2100,
|
|
'likes' => 150,
|
|
'days_ago' => 3,
|
|
'body' => <<<'TEXT'
|
|
# The React job market in Iran: full-time employment or freelance
|
|
|
|
Almost every week someone asks me whether they should keep applying for React jobs in Iran or go independent. The honest answer is that both paths exist, they pay very differently, and the right choice depends mostly on your level and your runway, not on the framework. This is the market as I see it in 2026.
|
|
|
|
## What demand actually looks like
|
|
|
|
React is still the default for anything product shaped in Iran: dashboards, admin panels, SaaS products, and large e-commerce and content sites. Next.js is close to mandatory for anything public facing. But the market is smaller than it was a few years ago. Funding is tight, teams are small, and much of the supposed startup work is really maintenance on older products. The result is that the bar moved up. A junior React developer without strong fundamentals is struggling. A senior engineer who can own a feature from design to production is not struggling.
|
|
|
|
## The stacks that get you hired
|
|
|
|
- TypeScript everywhere, strict mode, no `any` in a pull request.
|
|
- The Next.js App Router with React Server Components, Server Actions and streaming, plus real judgement about where the client boundary belongs.
|
|
- Data layer competence: Prisma or Drizzle, SQL that is not a toy, and knowing when a query is the actual problem.
|
|
- Testing that is not decoration: Vitest or Jest with React Testing Library, and Playwright for the critical flows.
|
|
- Performance and observability: Core Web Vitals, caching strategy, bundle budgets, error tracking.
|
|
- Enough backend to never be blocked: Node, queues, cron, auth, object storage, and a deployment you can debug at 2am.
|
|
- Docker, CI pipelines and infrastructure as code, at least enough not to be the bottleneck.
|
|
|
|
Contract work usually asks for the full width of that list. That is why people here describe themselves as full stack even when the backend is one file.
|
|
|
|
## Compensation reality
|
|
|
|
For in-office roles in Tehran, a strong mid to senior React or Next.js engineer typically lands between 60 and 120 million Toman per month, with the top of that range concentrated in product companies and consultancies with foreign clients. Staff and lead roles go higher, but there are very few of them. Junior and mid roles cluster much lower, and the spread between tiers is wide.
|
|
|
|
Then there is remote work for Iranian contractors, where the real spread appears. Remote for an Iranian company usually pays less than the in-office equivalent, because you save them rent and they know it. Remote for a client abroad pays multiples more in hard currency, but the obstacles are concrete: sanctions, difficulty opening accounts and receiving payments, overlapping European hours, and interviews in English. It is not impossible, and plenty of engineers I know manage it, but it is not a default plan.
|
|
|
|
## Employment or freelance
|
|
|
|
- Under two years of real experience: take employment. You need code review, mentorship, and someone else owning the outages.
|
|
- Two to five years with a network: hybrid works best. Salary for stability, evenings or weekends for retainers.
|
|
- Senior, with reputation and roughly six months of runway: freelance can beat a salary, but only with a written contract, a deposit, and strict scope control.
|
|
- If you pay rent or family bills from this income: keep the salary. Freelance income is lumpy and a quiet month is normal, not a failure.
|
|
|
|
## The engine that actually gets offers
|
|
|
|
- Two or three deep case studies, each with the problem, the constraints, your decisions, and one number. Numbers land harder than screenshots.
|
|
- English, written first. Most remote conversations hire partly on how clearly you explain things in writing.
|
|
- One real open source contribution. Not a tutorial clone, a pull request or a small library with actual users.
|
|
- A clean LinkedIn and a portfolio site that loads fast. A slow portfolio is a bad signal in this field.
|
|
|
|
## Negotiating
|
|
|
|
Do not name your current salary first. Ask for the approved range. Remember that Iranian employees contribute to social insurance through payroll, which is a meaningful part of the package compared with invoicing as a freelancer, where you cover the full amount yourself. Ask about bonuses, working hours, leave, and whether they pay for your tools or training. With foreign clients, get the currency, rate and payment terms in writing before you start, and always take a deposit.
|
|
|
|
Choose employment when you still need to learn fast. Choose freelance when you already have the skill and the network. The market will not decide this for you.
|
|
|
|
## Key takeaways
|
|
- React is still the default for product work in Iran, but the bar moved up sharply for juniors without fundamentals.
|
|
- Learn the full width of the stack: data layer, real tests, performance and observability, plus enough backend to debug at 2am.
|
|
- Match the income model to your stage: employment early, hybrid in mid-career, freelance only with about six months of runway.
|
|
- Build two or three deep case studies, each ending in one number. Numbers land harder than screenshots.
|
|
- Never name your current salary first. Ask for the approved range, and price in the social insurance you contribute.
|
|
|
|
## FAQ
|
|
|
|
Q: React job or freelance in Iran?
|
|
A: It depends on your level and runway, not the framework. Under two years of experience, take employment because you need code review and mentorship. A senior with six months of runway can beat a salary, but only with a written contract.
|
|
|
|
Q: Is remote work abroad realistic from Iran?
|
|
A: It pays multiples more in hard currency, and plenty of engineers manage it, but it is not a default plan. The obstacles are concrete: sanctions, payment and account access, overlapping European hours, and interviews in English.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'Moving from WordPress to Next.js: a migration guide for Persian websites',
|
|
'slug' => 'wordpress-to-nextjs-migration',
|
|
'excerpt' => 'The staged path from a slow WordPress site to a fast Next.js one, keeping Persian content, Persian URLs and search traffic intact.',
|
|
'category' => 'react-nextjs',
|
|
'tags' => ['react', 'nextjs', 'performance'],
|
|
'cover' => 'WordPress to Next.js migration roadmap',
|
|
'views' => 2300,
|
|
'likes' => 170,
|
|
'days_ago' => 1,
|
|
'body' => <<<'TEXT'
|
|
# Moving from WordPress to Next.js: a migration guide for Persian websites
|
|
|
|
WordPress still runs a large share of the Persian web, from small company sites to large publishers. It got there for good reasons, but many of these sites score badly on Core Web Vitals because of the theme and page builder, not the content. This is the staged path I use when a client wants Next.js without losing search traffic.
|
|
|
|
## Why the question comes up so often
|
|
|
|
- WordPress dominates the Persian web, so most businesses already have years of URLs, backlinks and content they refuse to lose.
|
|
- Page builders like WPBakery, Elementor and Divi ship large CSS and JavaScript bundles, jQuery and enormous DOM trees. That is what kills LCP and INP, not the images or the hosting.
|
|
- Persian plugins for forms, sliders, SEO and translation each add weight, and each is a maintenance and security risk.
|
|
- The owner wants to edit content without touching code, and that need survives the migration.
|
|
|
|
## Stage one: audit and baseline
|
|
|
|
Record the numbers before changing anything, so you can prove the migration worked. Crawl the site and export every indexed URL with its status code, title and canonical. Pull a year of Search Console data and note the top landing pages. Run Lighthouse on a few representative templates with a mobile profile and save the LCP, INP and CLS values. Check the analytics setup, because that is what breaks silently in every migration.
|
|
|
|
## Stage two: get the content out
|
|
|
|
The REST API is the clean route for standard content: each post type is an endpoint, results are paginated, so script it and follow pages until you have everything. Watch for custom post types and advanced custom fields, since the default endpoint does not return custom fields and you must register them first. For a large site a WP-CLI export to JSON gives you the whole database in one file. Export media separately, keeping original filenames.
|
|
|
|
## Stage three: choose the content architecture
|
|
|
|
You have two honest options. Keep WordPress as a headless CMS and fetch content at build or request time: your client keeps the editor they know, you get the Next.js frontend, and you accept a moving target. Or import everything into markdown, MDX or a headless CMS and generate static pages, which is fastest when content changes only a few times a week. Most of my clients end up with static content plus a small editing tool for the pages that genuinely change.
|
|
|
|
## Stage four: routes, slugs and redirects
|
|
|
|
This is where migrations are won or lost. Map every old URL to a new one and keep the path structure identical so the work is mechanical. If you cannot preserve a URL, 301 it to the closest equivalent, never to the homepage. Keep Persian and Arabic slugs exactly as they were, unchanged and un-normalised, because altering them breaks links and makes the site look new to search engines. Do not forget pagination, archives, tag pages, feeds and attachment pages, all of which are usually indexed. Generate the new sitemap.
|
|
|
|
## Stage five: build it fast
|
|
|
|
Use static generation by default, adding revalidation only where content changes daily: the App Router with static rendering, plus incremental revalidation for pages like a news index. Serve images through the framework image component, sized per breakpoint, in modern formats. Set language and direction on the document element with `lang="fa"` and `dir="rtl"`, and write CSS with logical properties such as `margin-inline-start` instead of left and right, so one stylesheet works both ways.
|
|
|
|
## Persian typography, properly
|
|
|
|
Do not reach for the Google Fonts loader. Google Fonts is filtered on most Iranian networks, so a font fetched from a Google domain fails or falls back to a system font and flashes. Download a variable Persian font such as Vazirmatn, self host it, and register it with `next/font/local` so Next.js handles the preload and size adjust. One file, two or three weights, `font-display: swap`, and correct line height. Check Persian digits and calendar dates before launch.
|
|
|
|
## The gotchas
|
|
|
|
- Media URLs. Copy uploads to the new host or object storage, keep filenames identical, and fix hardcoded references in old posts. Stale image URLs cause mixed content warnings.
|
|
- Comment forms. Plugin based comments rarely survive. Decide early whether you keep comments, and if you do, plan a simple form plus moderation rather than porting the old system.
|
|
- Analytics. Google services are unreliable from inside Iran. Confirm your provider loads for your visitors, or self host a first party cookieless tool so you do not lose history and restart from zero.
|
|
- Search. The WordPress search endpoint will not exist. If the site relied on it, add a real index or accept site search.
|
|
- Mixed content and plain http URLs inside old content, plus inline styles and scripts nobody audited.
|
|
- Testing every redirect with curl, then a final Lighthouse run on the templates you measured at the start.
|
|
|
|
## What success looks like
|
|
|
|
Compare before and after on identical pages. On the sites I have moved, LCP typically drops from four or five seconds to under two, and INP improves even more because the page builder is gone. Traffic should be flat within a few weeks once redirects settle, and often grows because of the speed. Migrate one template at a time.
|
|
|
|
## Key takeaways
|
|
- Baseline before touching anything: export every indexed URL, a year of Search Console data, and LCP, INP and CLS per template.
|
|
- Page builders are what kill LCP and INP here, not images or hosting. Removing the builder does most of the work.
|
|
- Map every old URL and keep the path structure identical. Redirect to the closest equivalent, never to the homepage.
|
|
- Keep Persian and Arabic slugs unchanged and un-normalised, because normalising them breaks links and search equity.
|
|
- Use static generation by default, and add incremental revalidation only where content changes daily.
|
|
|
|
## FAQ
|
|
|
|
Q: Is migrating to Next.js worth it?
|
|
A: When Core Web Vitals are bad because of the theme and page builder rather than the content, and the owner wants speed without losing years of URLs and backlinks. LCP typically drops from four or five seconds to under two.
|
|
|
|
Q: Should I keep WordPress as a CMS?
|
|
A: Keep it headless and fetch content at build or request time, or import everything into markdown, MDX or a headless CMS and generate static pages. Most clients end up with static content plus a small editor.
|
|
TEXT,
|
|
],
|
|
|
|
// =================================================================
|
|
[
|
|
'title' => 'Clean Architecture in Laravel Without the Acronym Sprawl: A Folder Layout That Survives Real Projects',
|
|
'slug' => 'clean-architecture-laravel',
|
|
'excerpt' => 'A pragmatic folder split for Laravel that keeps Eloquent at the boundary, respects dependency direction, and avoids over-engineering small CRUD apps.',
|
|
'category' => 'backend-development',
|
|
'tags' => ['laravel', 'clean-code'],
|
|
'cover' => 'Clean architecture in Laravel',
|
|
'views' => 1940,
|
|
'likes' => 136,
|
|
'days_ago' => 8,
|
|
'body' => <<<'TEXT'
|
|
# Clean Architecture in Laravel Without the Acronym Sprawl: A Folder Layout That Survives Real Projects
|
|
|
|
Clean architecture is often taught with a wall of acronyms: entities, use cases, interfaces, adapters, ports. That is useful in theory, but in real Laravel projects it usually leads to over-engineering. The goal is not to tick boxes. The goal is to keep business logic independent from framework details so the codebase survives years of change.
|
|
|
|
## The pragmatic split
|
|
|
|
A simple, battle-tested approach is to split code into three core layers: Domain, Application, and Infrastructure. This keeps the dependency direction clear without inventing twenty namespaces.
|
|
|
|
Domain contains the core business concepts. This includes entities, value objects, enums, and domain rules. Nothing in Domain should depend on Laravel, Eloquent, HTTP, or external APIs. It should be pure PHP that represents your business.
|
|
|
|
Application contains the use cases: what the system does. This is where you coordinate workflows, apply business rules, and define interfaces for external dependencies. Application depends only on Domain. It does not know about controllers, jobs, or databases.
|
|
|
|
Infrastructure is the outermost layer. This is where Laravel lives: Eloquent models, repositories, jobs, HTTP clients, services that call third parties, and framework-specific code. Infrastructure implements the interfaces defined in Application and depends on both Application and Domain.
|
|
|
|
## Keeping Eloquent in the repository boundary
|
|
|
|
One of the most common mistakes is letting Eloquent leak everywhere. Eloquent models are convenient, but they couple your business logic to the database schema and framework features. The pragmatic fix is to treat Eloquent as an implementation detail.
|
|
|
|
Define repository interfaces in the Application layer. For example, an OrderRepository interface that describes methods like findById or save. Implement that interface in Infrastructure using Eloquent models. Your use cases depend only on the interface, not on the model classes. This makes it easy to swap implementations or test use cases with in-memory fakes.
|
|
|
|
Also, avoid returning Eloquent collections or models from repositories to the Application layer. Map them to Domain entities or simple DTOs. This keeps the boundary clean and prevents lazy loading or framework behavior from creeping into your business logic.
|
|
|
|
## Dependency direction matters
|
|
|
|
The key rule is: dependencies point inward. Infrastructure can depend on Application and Domain. Application can depend only on Domain. Domain depends on nothing outside itself. This is the core of keeping your code decoupled from the framework.
|
|
|
|
Controllers, routes, jobs, and commands live in Infrastructure. They should be thin orchestrators. They call Application use cases, map HTTP requests to DTOs, and return responses. If your controllers are doing validation, calculations, or complex queries, that logic probably belongs in Application or Domain.
|
|
|
|
## When not to over-layer
|
|
|
|
Clean architecture has a cost. For a small CRUD app, adding three layers for every feature creates unnecessary indirection. If your app is mostly data entry with little business logic, a traditional Laravel structure is perfectly fine.
|
|
|
|
The signal to add layers is complexity. If you have non-trivial business rules, multiple integrations, or the domain is likely to outlive the framework choice, the investment pays off. If you are still validating product-market fit, keep it simple and refactor toward these boundaries as complexity emerges.
|
|
|
|
## Practical folder layout
|
|
|
|
A minimal, maintainable structure looks like this. In app/, create Domain/, Application/, and Infrastructure/. Alternatively, use src/ if you prefer. Keep Laravel's existing directories where they make sense, but move business logic out.
|
|
|
|
Domain can hold Entities/, ValueObjects/, Enums/, and domain-specific exceptions. Application can hold UseCases/, Contracts/ (interfaces), DTOs/, and Policies/. Infrastructure can hold Repositories/, Services/, Jobs/, Http/Controllers/, and any framework-specific adapters.
|
|
|
|
This keeps namespaces clear and makes it obvious where new code belongs. New developers can follow the dependency rule without memorizing every acronym from the textbooks.
|
|
|
|
## Key takeaways
|
|
|
|
- Split into Domain, Application, Infrastructure to keep business logic framework-agnostic.
|
|
- Define repository interfaces in Application and implement them with Eloquent in Infrastructure.
|
|
- Map Eloquent models to Domain entities or DTOs at the boundary, never leak models inward.
|
|
- Follow the inward dependency rule: Infrastructure depends outward, Domain depends on nothing.
|
|
- Only layer when business complexity justifies it. Small CRUD apps do not need full clean architecture.
|
|
|
|
## FAQ
|
|
|
|
Q: Do I have to throw away Eloquent?
|
|
A: No. Eloquent is a great ORM. Keep it in Infrastructure as an implementation detail behind repository interfaces.
|
|
|
|
Q: Is this the same as hexagonal architecture?
|
|
A: Similar idea, different naming. The goal is ports and adapters: isolate the core from external concerns. This pragmatic split captures that without acronym sprawl.
|
|
|
|
Q: How do I test this structure?
|
|
A: Test Domain and Application with fast unit tests (no Laravel). Test Infrastructure with integration tests that use the database or mocks as needed. This keeps your feedback loop fast.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'A Git Branching and Code Review Workflow That Scales Past Five Developers',
|
|
'slug' => 'git-branching-and-reviews',
|
|
'excerpt' => 'Branching strategy is not the bottleneck, review quality is. Short-lived branches, atomic commits, protected main and automated checks take a five person team to twenty without the arguments.',
|
|
'category' => 'engineering-practices',
|
|
'tags' => ['git', 'clean-code'],
|
|
'cover' => 'Git workflow and code reviews',
|
|
'views' => 2340,
|
|
'likes' => 155,
|
|
'days_ago' => 17,
|
|
'body' => <<<'TEXT'
|
|
# A Git Branching and Code Review Workflow That Scales Past Five Developers
|
|
|
|
Most teams blame branching strategy when they hit a wall around six developers. The thing that actually degrades with headcount is the quality and the latency of code review. Here is the workflow I install on every project, and the reason behind each piece.
|
|
|
|
## Short-lived branches beat long-lived ones
|
|
|
|
A branch that lives three weeks carries three weeks of changes you have not seen and ends in a painful merge. It exists so you can work in parallel, then hand something reviewable to the next person.
|
|
|
|
- Open the branch the day you start and merge it within a day.
|
|
- If it will not merge quickly, the change is too big. Split it.
|
|
- Long-lived experiment branches only work if that code never ships in between.
|
|
- Delete branches on merge, or nobody can tell which work is real.
|
|
|
|
## Trunk based versus feature branches, in practice
|
|
|
|
They are not opposites. Trunk based means main is always releasable, and short branches are perfectly fine inside that. You branch from main for a few hours, open a pull request, merge after review. Avoid the other extreme, where every developer keeps a personal branch for months. That model works until two people touch the same migration.
|
|
|
|
## Commits that are atomic and reviewable
|
|
|
|
A commit is a unit of meaning, not a unit of time. One thing, tests passing on their own, revertable on their own. That property is what gives you bisect and clean reverts.
|
|
|
|
- Separate a refactor from a behaviour change.
|
|
- Write the message for whoever runs bisect six months from now.
|
|
- Why it changed matters more than what the diff already shows.
|
|
- Keep history short. Ten commits of a day's work is fine.
|
|
|
|
## What a good review actually checks
|
|
|
|
Review exists for correctness and shared understanding, not formatting. A formatter in CI already owns indentation, import order and line length. Reviewers who spend their attention there leave the real problems untouched.
|
|
|
|
- Does it do what the ticket says, including the unwritten parts, and nothing else?
|
|
- What happens on empty input, very large input and concurrent requests?
|
|
- Do the tests cover behaviour, or do they just restate the implementation?
|
|
- Is anything sensitive in the diff, a token, a personal identifier, an unbounded query?
|
|
- Will a newcomer understand this in six months?
|
|
|
|
Comments should say what and why, never only what. A review full of restated lines is noise, and noisy reviews get skimmed.
|
|
|
|
## Protecting main and automating the boring checks
|
|
|
|
The cheapest way to speed up review is to remove the questions a reviewer should never have to ask. Anything mechanical belongs in CI, because a human should not spend a review cycle on a missing newline.
|
|
|
|
- Require a pull request for main with at least one approval.
|
|
- Block direct pushes to main.
|
|
- Make format, lint, typecheck and tests required status checks.
|
|
- Keep the pipeline under ten minutes and parallelize as it grows.
|
|
- Merge with squash or rebase so main stays linear.
|
|
|
|
## Key takeaways
|
|
|
|
- Branch for hours, not weeks, because review cost scales with diff size.
|
|
- Keep main always releasable and merge small branches into it daily.
|
|
- Write atomic commits with messages aimed at a future bisect.
|
|
- Review behaviour and risk, and let the formatter own style.
|
|
- Automate every mechanical check so reviewer attention goes to correctness.
|
|
|
|
## FAQ
|
|
|
|
Q: Is trunk based development workable for a team that releases monthly?
|
|
|
|
A: Yes, and it fits monthly releases better than long-lived branches do. You merge to main daily and control what goes live with tags or feature flags, so main stays releasable while the release happens on your schedule. A monthly cycle is a release concern, not a branching concern.
|
|
|
|
Q: Our reviews are slow, should we require two approvals?
|
|
|
|
A: Not first. Slow reviews usually mean the diff is too large, the ticket is unclear or the author asked too late. Fix those and make sure mechanical checks run in CI so reviewers are not acting as linters. Only then is tightening rules for migrations and auth code sensible.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'SQL Indexes That Make Queries Fast: A Practical Guide With Laravel',
|
|
'slug' => 'sql-indexes-database-performance',
|
|
'excerpt' => 'A slow Laravel endpoint is almost never a slow server. Here is how to read EXPLAIN, order composite index columns correctly, add covering indexes and index foreign keys without slowing your writes down.',
|
|
'category' => 'backend-development',
|
|
'tags' => ['database', 'performance'],
|
|
'cover' => 'SQL indexes for fast queries',
|
|
'views' => 1960,
|
|
'likes' => 128,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# SQL Indexes That Make Queries Fast: A Practical Guide With Laravel
|
|
|
|
Almost every slow endpoint I get asked about has the same cause, a table scan on a column with no index. Laravel makes that easy to write and easy to forget, because nobody notices until the table passes a hundred thousand rows.
|
|
|
|
## What an index actually does
|
|
|
|
MySQL and PostgreSQL store indexes in a B-tree, whose keys stay sorted and whose leaves sit next to each other in storage. That one property explains the behaviour: finding a single key touches a few pages instead of every row, and two conditions on one column are served by walking the tree once from the start of the range to its end.
|
|
|
|
The other half matters too: every insert and update must be written into every index, so an index is a tax you pay on writes to buy fast reads.
|
|
|
|
## Reading EXPLAIN without guessing
|
|
|
|
Run EXPLAIN on the real query with real parameters and read it top to bottom, looking at the access type, the estimated rows, the filtered percentage and the extra column.
|
|
|
|
- A sequential scan on a large table means no usable index. Check the column and the value type.
|
|
- An index scan with a huge row estimate means the index is not selective enough for the optimizer.
|
|
- Rows removed by a filter usually means a wildcard or a non-sargable expression.
|
|
- A temporary table or filesort means ORDER BY could not be served from index order, so fix the index first.
|
|
- A dependent subquery often points at an N plus one in Eloquent, one query per parent row.
|
|
|
|
## Composite index column order
|
|
|
|
A multi-column index is not several indexes, it is one sorted list, and the column order decides which queries it serves: equality conditions first, then one range column, then columns used only for sorting or covering.
|
|
|
|
- Filtering on a tenant column and a created_at range uses an index on both, because the range stops at the first ranged column.
|
|
- Filtering on a user column and sorting by created_at descending also works, since the engine walks the index backwards.
|
|
- Prepending an equality column often makes the old single-column index redundant.
|
|
- Test the direction you query, because mixing ascending and descending changes what the engine can do.
|
|
|
|
## Covering indexes
|
|
|
|
A covering index holds every column the query needs, so the database answers from the index and never visits the table. Add those columns to an existing index rather than creating another, and look for the word covering in the EXPLAIN extra column. The catch is write amplification, so this belongs on your few hot queries.
|
|
|
|
## Foreign keys and the cost of over-indexing
|
|
|
|
Foreign key columns need indexes for a reason unrelated to convenience: when a row is deleted, the engine must prove no child rows point at it, and without an index that check becomes a table scan while holding locks.
|
|
|
|
- Index every foreign key column and every join column, this is the cheapest win in the system.
|
|
- Index the columns you filter, sort and join, but not columns you only select.
|
|
- In Laravel put indexes in migrations, not in a manual console session.
|
|
- Log every query in tests, which catches N plus one regressions before production.
|
|
|
|
## Key takeaways
|
|
|
|
- An index is a B-tree, so sorting and range scans get cheap while every write pays.
|
|
- Read access type, row estimate and extra in EXPLAIN before touching code.
|
|
- Equality columns first, then one range column, then sorting columns.
|
|
- Covering indexes answer without touching the table, so keep them on hot paths.
|
|
- Index every foreign key and keep the total small enough that writes stay fast.
|
|
|
|
## FAQ
|
|
|
|
Q: How do I find out which indexes are actually used in production?
|
|
|
|
A: Enable the performance schema or your provider slow query log, then compare the important queries with your index definitions. In MySQL it gives a per-table counter for unused indexes, and dropping them after a representative traffic window is the safest way to remove an index that only slows writes.
|
|
|
|
Q: Is it bad to index every column that appears in a WHERE clause?
|
|
|
|
A: It becomes bad as soon as write volume matters, because every index is updated on each insert and update. Ask instead which queries are frequent or slow, since a single well-ordered composite index usually serves several conditions at once.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'TypeScript Beyond the Basics: Generics, Utility Types and Strict Mode in Real Projects',
|
|
'slug' => 'typescript-advanced-patterns',
|
|
'excerpt' => 'Most teams use TypeScript as a linter and stop there. Generics that preserve your domain types, a short set of utility types, and the two compiler flags people skip are what turn the compiler into a refactoring tool.',
|
|
'category' => 'frontend-development',
|
|
'tags' => ['typescript', 'clean-code'],
|
|
'cover' => 'TypeScript patterns for real projects',
|
|
'views' => 2180,
|
|
'likes' => 142,
|
|
'days_ago' => 4,
|
|
'body' => <<<'TEXT'
|
|
# TypeScript Beyond the Basics: Generics, Utility Types and Strict Mode in Real Projects
|
|
|
|
Most teams adopt TypeScript for autocomplete and to stop shipping the classic string versus number mistakes. Six months later the codebase is full of any casts and a compiler config nobody dares to touch. That gap is vocabulary, not effort.
|
|
|
|
## Generics that earn their keep
|
|
|
|
A generic earns its place when one piece of logic must serve several shapes without any of them losing type information. If you end the implementation with a cast, you needed a plain function.
|
|
|
|
- A repository that takes the entity type once and returns it from every method.
|
|
- A form builder where each field declares its value type and the result is inferred.
|
|
- A table component taking a row type plus accessors, so sorting stays correct per column.
|
|
- A typed event emitter whose map defines payloads and legal event names.
|
|
|
|
Two constraints do the heavy lifting, since keyof T accepts only keys the type really has and extends string keeps an argument inside a known family.
|
|
|
|
## The utility types you actually need
|
|
|
|
Nobody memorises a hundred of these. A short set covers almost everything, and composing them in one named alias beats inventing a type per model.
|
|
|
|
- Partial for update payloads and form models.
|
|
- Pick and Omit to build request DTOs without repeating a field name.
|
|
- ReturnType and Parameters so a hook documents its own shape once.
|
|
- NonNullable for values that come back from a nullable column.
|
|
- Record for a typed dictionary instead of a permissive index signature.
|
|
- Awaited to unwrap promises returned by clients that return promises.
|
|
|
|
## The two compiler flags people skip
|
|
|
|
Strict mode is the baseline. The upgrade almost nobody enables is noUncheckedIndexedAccess, and it catches the most real bugs, because reading outside a known range is the commonest source of runtime undefined.
|
|
|
|
- Array and record access becomes value or undefined, so out-of-range reads fail to compile.
|
|
- Strict null checks force you to handle the missing case instead of asserting it away.
|
|
- exactOptionalPropertyTypes blocks assigning undefined to an optional field.
|
|
- noImplicitOverride and the switch fallthrough flag clean up inheritance mistakes.
|
|
|
|
Turning them on for an old codebase produces a burst of errors, so enable them for new modules and fix files as you touch them.
|
|
|
|
## Discriminated unions beat optional fields
|
|
|
|
An object with three booleans and four nullable fields has eight meaningful states and the compiler checks none of them. A union with a literal status makes the invalid combinations type errors.
|
|
|
|
- Model a payment as created, captured or refunded, not a status string with nullable fields.
|
|
- Model a form flow as a union of step objects, each carrying only its own data.
|
|
- Narrow with a switch on the discriminant and the union narrows inside each branch.
|
|
|
|
## Where to stop
|
|
|
|
Type-level programming has a ceiling, and crossing it is the fastest way to make a team distrust its own types.
|
|
|
|
- Do not build a type that needs a comment longer than the code it replaces.
|
|
- Do not hide one implementation behind a generic parameter until a second one exists.
|
|
- Do not encode business rules in types, encode states and relationships.
|
|
- Parse external data once at the boundary, then use that type everywhere else.
|
|
|
|
## Key takeaways
|
|
|
|
- Add a generic only when shapes share behaviour and stay distinguishable.
|
|
- Keep a short set of utility types and compose them.
|
|
- Turn on noUncheckedIndexedAccess first, then the other strict flags file by file.
|
|
- Replace clusters of nullable fields with discriminated unions.
|
|
- Stop before the types get harder to read than the logic.
|
|
|
|
## FAQ
|
|
|
|
Q: Does heavy type level code slow the compiler down on a large codebase?
|
|
|
|
A: Sometimes, and the cost lands on the largest files, not the whole project. Deep mapped types and generics instantiated with large unions are the usual culprits, so simplify a couple of aliases rather than removing the flags.
|
|
|
|
Q: Should I enable strict mode on an existing codebase at once?
|
|
|
|
A: Not at once. Keep the flags out of the global build for legacy folders, apply them to new modules immediately, and fix errors in small batches as you touch each file.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'What Actually Happens When the Browser Loads a Page: From DNS to a 90 Lighthouse Score',
|
|
'slug' => 'how-the-browser-loads-a-page',
|
|
'excerpt' => 'A practical breakdown of browser page loading with actionable steps to improve performance and Core Web Vitals for better SEO and UX.',
|
|
'category' => 'web-performance-seo',
|
|
'tags' => ['performance', 'seo'],
|
|
'cover' => 'How a browser loads a page',
|
|
'views' => 2150,
|
|
'likes' => 138,
|
|
'days_ago' => 15,
|
|
'body' => <<<'TEXT'
|
|
# What Actually Happens When the Browser Loads a Page: From DNS to a 90 Lighthouse Score
|
|
|
|
When a user types a URL and hits enter, a lot happens in milliseconds. Understanding this process is not just academic. It helps you debug slow sites, prioritize fixes, and improve both user experience and SEO. Here is what actually happens, step by step, and how each stage affects performance.
|
|
|
|
## DNS lookup and initial connection
|
|
|
|
The first step is resolving the domain name to an IP address. The browser checks its cache, the OS cache, the router, and finally DNS servers. Slow DNS adds unnecessary latency, especially on mobile networks.
|
|
|
|
Once the IP is known, the browser establishes a TCP connection. For HTTPS sites, this includes TLS handshake to negotiate encryption. TLS 1.3 has reduced handshake round trips significantly compared to older versions. Connection reuse, through keep-alive or HTTP/2 multiplexing, prevents paying this cost for every resource.
|
|
|
|
## HTTP requests and connection protocols
|
|
|
|
Modern sites use HTTP/2 or HTTP/3. With HTTP/1.1, browsers limited concurrent requests per domain, leading to waterfall bottlenecks. HTTP/2 allows multiplexing multiple requests over one connection. HTTP/3 moves to QUIC over UDP, reducing head-of-line blocking and improving performance on unreliable networks.
|
|
|
|
The browser first requests the HTML document. This is usually a small text file, but it is the key that unlocks everything else. How the server delivers it, compression (like gzip or Brotli), and caching headers all affect first load time.
|
|
|
|
## HTML parsing and building the DOM
|
|
|
|
As the browser receives HTML bytes, it parses them into tokens, then into the DOM tree. This is a streaming process; the browser can start parsing before the entire document is downloaded. However, parsing is blocked when it encounters synchronous scripts without defer or async.
|
|
|
|
While parsing HTML, the browser discovers references to external resources: stylesheets, scripts, images, fonts, and more. Each discovery triggers a new request, which can either be queued or started depending on the protocol and priority.
|
|
|
|
## Critical CSS and render-blocking resources
|
|
|
|
CSS is render-blocking by default. The browser cannot render content until it has the CSSOM (CSS Object Model) constructed. Large, unoptimized stylesheets delay the first paint. A common optimization is to extract and inline critical CSS for above-the-fold content, then load the rest asynchronously.
|
|
|
|
JavaScript is even more impactful. Synchronous scripts block HTML parsing and can delay rendering. Using script type=module, defer, or async changes when execution happens. defer preserves execution order and runs after DOM parsing. async runs as soon as it is downloaded, without preserving order. Moving non-critical scripts to the end or deferring them is key to improving perceived performance.
|
|
|
|
## Preloading, prefetching, and resource hints
|
|
|
|
Not all resources are discovered at the same time. The browser builds a preload scanner that looks ahead in the HTML to discover resources earlier. You can also give explicit hints: link rel=preload for critical resources like fonts or hero images, preconnect to establish connections early, and prefetch for resources likely needed on the next page.
|
|
|
|
These hints help the browser prioritize what matters most for the current view. Used correctly, they reduce load delays without overloading the network.
|
|
|
|
## Images, fonts, and layout stability
|
|
|
|
Images often account for the largest bytes. Optimizations like modern formats (WebP, AVIF), responsive srcset, lazy loading offscreen images, and proper sizing reduce both bytes and layout shifts. Decoding large images can also block the main thread; using decoding=async or proper sizing helps.
|
|
|
|
Fonts can cause invisible text or layout shifts if not handled well. font-display: swap shows fallback text quickly while the web font loads, improving perceived performance. Preloading critical fonts reduces the chance of FOIT (Flash of Invisible Text).
|
|
|
|
Cumulative Layout Shift (CLS) comes from content shifting after initial render. Reserving space for images, ads, or dynamic content is one of the most effective ways to improve CLS.
|
|
|
|
## The rendering pipeline and Core Web Vitals
|
|
|
|
Once CSSOM and DOM are ready, the browser constructs the render tree, computes layout, paints pixels, and composites layers. This happens frame by frame. Long tasks on the main thread block interactivity.
|
|
|
|
Core Web Vitals map directly to this pipeline. Largest Contentful Paint (LCP) measures when the largest visible element loads, often a hero image or heading. Interaction to Next Paint (INP) measures responsiveness to user input. Cumulative Layout Shift (CLS) measures visual stability. These metrics heavily influence Lighthouse scores and SEO rankings.
|
|
|
|
## Getting to a 90 Lighthouse score
|
|
|
|
Reaching 90+ is achievable by focusing on high-impact fixes. Optimize images and serve them in modern formats. Defer or lazy-load non-critical JavaScript. Inline critical CSS and eliminate render-blocking resources. Use caching headers and a CDN to reduce Time to First Byte (TTFB). Preconnect to third-party domains and preload critical assets. Finally, minimize layout shifts by reserving space for dynamic elements.
|
|
|
|
The key is not doing everything. It is fixing what blocks the critical path for your specific page. Profile with Chrome DevTools and Lighthouse, measure, then iterate.
|
|
|
|
## Key takeaways
|
|
|
|
- DNS, TCP, and TLS add connection latency; reuse connections and use HTTP/2 or HTTP/3.
|
|
- HTML parsing is streaming but blocked by synchronous scripts; use defer/async for non-critical JS.
|
|
- CSS blocks rendering; inline critical CSS and load the rest efficiently.
|
|
- Preload critical assets and preconnect to important origins to reduce wait time.
|
|
- Optimize images, fonts, and layout to improve LCP, INP, and CLS for better Lighthouse scores.
|
|
|
|
## FAQ
|
|
|
|
Q: What is the single biggest factor for LCP?
|
|
A: Usually the hero image or large visible element. Optimizing its size, format, and load priority has the most impact.
|
|
|
|
Q: Should I use async or defer for scripts?
|
|
A: Use defer for scripts that depend on DOM order. Use async for independent scripts like analytics that do not interact with page structure immediately.
|
|
|
|
Q: How does HTTP/3 help performance?
|
|
A: HTTP/3 uses QUIC over UDP, reducing head-of-line blocking and recovering faster from packet loss, especially on mobile or unreliable networks.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'Test-Driven Development When It Actually Pays Off: Writing Testable Code Without the Dogma',
|
|
'slug' => 'tdd-writing-testable-code',
|
|
'excerpt' => 'Learn when TDD speeds you up versus when it slows you down, and how the three-layer rule keeps tests fast and useful in real projects.',
|
|
'category' => 'engineering-practices',
|
|
'tags' => ['testing', 'clean-code'],
|
|
'cover' => 'TDD and testable code',
|
|
'views' => 1480,
|
|
'likes' => 112,
|
|
'days_ago' => 12,
|
|
'body' => <<<'TEXT'
|
|
# Test-Driven Development When It Actually Pays Off: Writing Testable Code Without the Dogma
|
|
|
|
The TDD debates tend to swing between two extremes. On one end, people treat it as a religious practice. On the other end, people dismiss it as unnecessary overhead. The truth is much more practical: TDD pays off in some domains, adds ceremony in others, and the value is not writing tests first. The value is being forced to write testable code from the start.
|
|
|
|
## When TDD actually helps
|
|
|
|
The biggest return comes from code that is likely to change or break. Business rules are a good example. Pricing calculations, tax logic, discounts, or validation rules tend to have many edge cases. Writing a failing test first makes those rules explicit and prevents regressions when requirements evolve.
|
|
|
|
Parsing and transformation work also benefits. When you convert between formats, extract data, or normalize inputs, TDD lets you build up complex cases incrementally. Each test locks in behavior and gives you confidence to refactor without fear.
|
|
|
|
Refactoring legacy code is another area where TDD shines. If you can put a small safety net of fast tests around a module first, you can restructure it safely. Finally, anything with high regression risk, like authentication, authorization, or financial calculations, is worth the upfront investment.
|
|
|
|
## When it adds unnecessary ceremony
|
|
|
|
Not all code deserves the red-green-refactor cycle. Throwaway UI prototypes, quick scripts for one-time data migration, or experiments you might throw away in a day rarely justify writing tests first. The same goes for purely presentational components where behavior is trivial and changes constantly based on feedback.
|
|
|
|
The cost is not just writing tests. It is the context switching and the time spent maintaining tests that no longer reflect useful behavior. In those cases, it is better to write tests after stabilizing the behavior, or skip them entirely until the design solidifies.
|
|
|
|
## The three-layer rule for testability
|
|
|
|
The simplest way to write testable code without dogma is to separate concerns into three layers. The logic layer contains pure business rules with no side effects. This is where TDD is cheapest and most powerful because tests run instantly and have no dependencies.
|
|
|
|
The effects layer handles I/O: database access, API calls, file system, queues, and external services. These are slower and often require mocks or test doubles. Keep this layer thin and push complexity to the logic layer.
|
|
|
|
The interface layer is what talks to the outside world, like controllers, CLI commands, or UI handlers. This layer should orchestrate calls and map data. If most of your complexity lives in logic, your interface tests stay small and your integration tests stay focused.
|
|
|
|
## Naming and assertion quality
|
|
|
|
Tests are documentation for future developers. Good test names describe behavior, not implementation. Instead of testingFunctionReturnsTrue, say something like shouldApplyDiscountWhenSubtotalExceedsThreshold. This makes failures readable and intent clear.
|
|
|
|
Assertions matter just as much. Prefer clear, specific assertions over generic ones. Avoid asserting on implementation details like private methods or internal object structure. Test observable behavior: inputs, outputs, side effects that matter, or state changes visible through the public API. This keeps tests resilient to refactors.
|
|
|
|
## Keep tests fast so they run on every commit
|
|
|
|
Speed is the single most important property of a useful test suite. If tests take minutes, they will only run in CI. If they take seconds, they will run before every commit. That is the difference between catching bugs early and discovering them hours later.
|
|
|
|
To keep them fast, avoid hitting real databases, networks, or file systems in unit tests. Use fakes, stubs, or in-memory implementations. Reserve slow tests for critical integration paths and mark them separately. A fast feedback loop is what makes TDD feel like it speeds you up instead of slowing you down.
|
|
|
|
## Key takeaways
|
|
|
|
- Use TDD where behavior is stable enough to matter: business rules, parsing, refactors, and high regression areas.
|
|
- Skip or defer TDD for throwaway UI, prototypes, or rapidly changing experiments.
|
|
- Apply the three-layer rule: logic, effects, and interface to isolate complexity.
|
|
- Write behavior-focused test names and assert on observable outcomes, not internals.
|
|
- Prioritize speed so your test suite runs in every commit and keeps feedback tight.
|
|
|
|
## FAQ
|
|
|
|
Q: Should I always write tests first?
|
|
A: No. Write tests first when the requirements are clear enough to define expected behavior. If the design is still in flux, iterate on the implementation first and add tests once the shape stabilizes.
|
|
|
|
Q: How much test coverage is enough?
|
|
A: Focus on covering critical paths and edge cases, not chasing 100 percent. High coverage of trivial code is low value. Good coverage of business-critical logic prevents the regressions that actually hurt users.
|
|
|
|
Q: Do I need TDD to write testable code?
|
|
A: No. TDD is a discipline that tends to produce testable code, but you can also refactor toward testability. The goal is testable code with fast, meaningful tests, not strict adherence to the dogma.
|
|
TEXT,
|
|
],
|
|
// Persian posts
|
|
// =================================================================
|
|
[
|
|
'title' => 'نکست و اپ روتر: چرا سرور کامپوننتها نحوهی ساخت وبسایت را تغییر دادند',
|
|
'slug' => 'nextjs-app-router-server-components-fa',
|
|
'excerpt' => 'اپ روتر و سرور کامپوننتها فقط APIهای جدید نیستند؛ محل اجرای کد را تغییر میدهند. در این مقاله میبینید چطور حجم باندل کم، بازیابی داده سادهتر و صفحهها سریعتر شدند.',
|
|
'category' => 'react-nextjs-fa',
|
|
'tags' => ['nextjs-fa', 'react-fa'],
|
|
'cover' => 'راهنمای اپ روتر نکست',
|
|
'views' => 3100,
|
|
'likes' => 205,
|
|
'days_ago' => 2,
|
|
'body' => <<<'TEXT'
|
|
# اپ روتر در نکست
|
|
## چه چیزی واقعاً تغییر کرد
|
|
جابهجایی از روتر پیجها به اپ روتر بزرگترین تغییر نکست از زمان انتشارش است. لِیآوتها قابل اشتراک شدند، حالتهای بارگذاری تودرتو به امری عادی تبدیل شدند و سرور کامپوننتها بیشتر کار رندرینگ را از کلاینت برداشتند.
|
|
|
|
## حلقهی اول: کد شما کجا اجرا میشود؟
|
|
- کامپوننتها پیشفرض کامپوننت سرور هستند و فقط HTML ارسال میکنند.
|
|
- باندل جاواسکریپت دیگر کدی را که لازم نیست در مرورگر اجرا شود حمل نمیکند.
|
|
- «use client» حالا انتخابِ صریح است، نه رفتار پیشفرض.
|
|
|
|
## بازیابی دادهی سادهتر
|
|
در روتر پیجها برای هر صفحه باید `getServerSideProps` یا `getStaticProps` جدا مینوشتیم. در اپ روتر مستقیم داخل کامپوننت داده میگیریم و خود نکست درخواستها را یکتا میکند و کش میکند. همین یک دسته از باگهای سالهانرمافزار را حذف کرد.
|
|
|
|
## نتیجهی قابل اندازهگیری
|
|
ملموسترین دستاورد کاهش حجم باندل بود. صفحهی اصلی همین وبسایت حدود ۱۸۰ کیلوبایت جاواسکریپت کمتر تحویل میدهد و بزرگترین محتوای نقاشیشده از ۲٫۴ ثانیه به حدود ۱٫۱ ثانیه در موبایل محدودشده رسید.
|
|
|
|
## چه زمانی از کامپوننت کلاینت نگه داریم؟
|
|
- فرمهای تعاملی با بهروزرسانی خوشبینانه.
|
|
- کامپوننتهایی که به رویدادهای مرورگر مثل اسکرول گوش میدهند.
|
|
- هر چیزی که از Context برای وضعیتی که مدام تغییر میکند استفاده میکند.
|
|
|
|
سرور-اول پیشفرض عالیای است، اما «use client» در مرزِ درست همچنان انتخابِ صحیح است. مهارت این است که این مرز را کجا بگذاری.
|
|
|
|
## جمعبندی
|
|
به مرز سرور و کلاینت به چشم یک تصمیم عملکردی نگاه کن، نه یک مد. رندر روی سرور بهعنوان پیشفرض و ارسال فقط آنچه واقعاً به مرورگر نیاز دارد، الگویی است که با محصول هم رشد میکند.
|
|
|
|
## نکات کلیدی
|
|
- کامپوننتها بهپیشفرض روی سرور رندر میشوند، پس use client را آگاهانه و فقط در مرز درست انتخاب کن.
|
|
- داده را مستقیم داخل خود کامپوننت بگیر و بگذار نکست درخواستها را یکتا و کش کند.
|
|
- مهاجرت را با حجم باندل و LCP بسنج؛ صفحهی اصلی این وبلاگ حدود ۱۸۰ کیلوبایت جاواسکریپت کم کرد.
|
|
- کلاینت کامپوننت را فقط برای فرم تعاملی، شنوندهی رویداد مرورگر و Context با تغییر مکرر نگه دار.
|
|
- مرز سرور و کلاینت را یک تصمیم عملکردی ببین، نه یک مُد گذرا.
|
|
|
|
## FAQ
|
|
|
|
Q: آیا در اپ روتر هنوز به getServerSideProps یا getStaticProps نیاز دارم؟
|
|
A: نه. در اپ روتر مستقیم داخل کامپوننت داده میگیریم و خود نکست درخواستها را یکتا و کش میکند. این کار هم قدم جداگانهی بازیابی داده را حذف میکند و هم یک دسته کامل از باگهای سالهانرمافزار را، و جاواسکریپت غیرضروری را از صفحه بیرون نگه میدارد.
|
|
|
|
Q: از کجا بفهمم یک کامپوننت باید کلاینت کامپوننت باشد؟
|
|
A: بپرس کار باید کجا اجرا شود. use client را برای فرمهای تعاملی با بهروزرسانی خوشبینانه، کامپوننتهایی که به رویدادهای مرورگر مثل اسکرول گوش میدهند و هر چیزی که از Context برای وضعیت مدامتغییرکننده استفاده میکند نگه دار. بقیه میتواند روی سرور بماند.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'وب وایتلهای اصلی؛ راهنمای عملی LCP، INP و CLS',
|
|
'slug' => 'core-web-vitals-practical-guide-fa',
|
|
'excerpt' => 'LCP، INP و CLS سنجههایی هستند که بازخورد واقعی کاربر را میسنجند. این راهنما توضیح میدهد هر کدام چه چیزی را اندازه میگیرند و چه اصلاحهای مشخصی نتیجه را تغییر میدهند.',
|
|
'category' => 'frontend-fa',
|
|
'tags' => ['performance-fa', 'seo-fa'],
|
|
'cover' => 'راهنمای وب وایتلها',
|
|
'views' => 5200,
|
|
'likes' => 460,
|
|
'days_ago' => 5,
|
|
'body' => <<<'TEXT'
|
|
# وب وایتلهای اصلی؛ راهنمای عملی LCP، INP و CLS
|
|
## چرا این سه سنجه مهم هستند
|
|
گوگل از وب وایتلها بهعنوان سیگنال تجربهی کاربر در رتبهبندی استفاده میکند. این سنجهها چیزی را توصیف میکنند که کاربران واقعی تجربه میکنند، نه فقط نتیجهی یک تست آزمایشگاهی، پس بهبود آنها کارِ واقعی روی محصول است.
|
|
|
|
## Largest Contentful Paint (LCP)
|
|
LCP زمان بارگذاری بزرگترین عنصر بالای صفحه را اندازه میگیرد. هدف زیر ۲٫۵ ثانیه است.
|
|
- تصویر قهرمان و استایلشیتِ مؤثر روی آن را از قبل پیشبارگذاری کن.
|
|
- تصاویر را با ابعاد درست و فرمت مدرن تحویل بده.
|
|
- اسکریپتهای شخص ثالثِ بلاککننده را از مسیر بحرانی حذف کن.
|
|
|
|
## INP یا فاصله تا Paint بعدی
|
|
INP جایگزین FID شده و بدترین پاسخ به تعامل کاربر را اندازه میگیرد. حد خوب ۲۰۰ میلیثانیه است.
|
|
- کارهای طولانی روی ترد اصلی را زیر ۵۰ میلیثانیه نگه دار.
|
|
- کارهای غیرضروری را تا بعد از تعاملیشدن صفحه عقب بینداز.
|
|
- بهجای اجرای هندلر گران روی هر رویداد، آن را debounce کن.
|
|
|
|
## Cumulative Layout Shift (CLS)
|
|
CLS به صفحههایی پاداش میدهد که هنگام بارگذاری نمیپرند. امتیاز زیر ۰٫۱ خوب محسوب میشود.
|
|
- برای تصاویر و محتوای جاسازیشده با ابعاد صریح فضا رزرو کن.
|
|
- از درج محتوا بالای محتوای موجود پس از شروع بارگذاری خودداری کن.
|
|
- با نگهداشتن متریکهای جایگزینِ فونت، از جابهجایی متن جلوگیری کن.
|
|
|
|
## چطور کارت را چک کنی
|
|
برای یک بررسی سریع از Lighthouse استفاده کن و بعد آن را با دادهی میدانی CrUX ترافیک واقعی خودت مقایسه کن. عملکرد میدانی همان چیزی است که موتور جستوجو نهایتاً میبیند.
|
|
|
|
## جمعبندی
|
|
عملکرد یک چکلیست یکباره نیست. هدفها را مشخص کن، سنجهها را به CI اضافه کن و هر انتشار که آنها را عقب میبرد را یک باگ حساب کن.
|
|
|
|
## نکات کلیدی
|
|
- سنجهها را با دادهی میدانی قضاوت کن، چون وب وایتلها تجربهی واقعی کاربر را توصیف میکنند نه نتیجهی تست آزمایشگاهی.
|
|
- تصویر قهرمان و استایلشیتِ مؤثر روی آن را پیشبارگذاری کن و اسکریپتهای بلاککننده را از مسیر بحرانی بیرون ببر.
|
|
- کارهای طولانی روی ترد اصلی را زیر ۵۰ میلیثانیه نگه دار و هندلرهای گران را debounce کن.
|
|
- برای تصاویر و محتوای جاسازیشده فضای صریح رزرو کن تا چیدمان جابهجا نشود و CLS زیر ۰٫۱ بماند.
|
|
- سنجهها را به CI اضافه کن و هر انتشاری که آنها را عقب میبرد را باگ حساب کن.
|
|
|
|
## FAQ
|
|
|
|
Q: برای بررسی کار، Lighthouse بهتر است یا CrUX؟
|
|
A: هر دو، اما برای کارهای متفاوت. Lighthouse یک بررسی سریع آزمایشگاهی میدهد که روی هر تغییر قابل اجراست، درحالیکه دادهی میدانی CrUX نشان میدهد ترافیک واقعی چه تجربهای داشته. عملکرد میدانی همان چیزی است که موتور جستوجو نهایتاً میبیند.
|
|
|
|
Q: چرا CLS من بعد از بازطراحی بدتر از LCP است؟
|
|
A: بیشتر جابهجایی چیدمان از محتوایی میآید که بدون فضای رزروشده میرسد. برای تصاویر و محتوای جاسازیشده ابعاد صریح بده، چیزی بالای محتوای موجود درج نکن و بگذار فونتها متریکهای جایگزینشان را نگه دارند تا متن با رسیدن فونت اصلی جابهجا نشود.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'طراحی APIهای REST با لاراول؛ اعتبارسنجی، ریسورس و محدودسازی نرخ',
|
|
'slug' => 'laravel-api-validation-resources-throttling-fa',
|
|
'excerpt' => 'قطعههایی که API لاراول را تمیز و امن نگه میدارند: فرم ریکوئست برای اعتبارسنجی، API ریسورس برای شکلِ پاسخِ یکدست و throttling برای حفاظت از مسیرهای عمومی.',
|
|
'category' => 'backend-fa',
|
|
'tags' => ['laravel-fa', 'clean-code-fa'],
|
|
'cover' => 'آموزش API با لاراول',
|
|
'views' => 1600,
|
|
'likes' => 130,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# طراحی APIهای REST با لاراول
|
|
## از شکل پاسخها شروع کن
|
|
سریعترین راه برای دلپسندکردن API نزد مصرفکننده، شکلِ پاسخِ پایدار است. API ریسورسهای لاراول یک نقطهی واحد برای تعریف آن میدهند تا فرانتاند هیچوقت مجبور نباشد حدس بزند که خروجی آبجکت است، آرایه است یا چیزی وسط.
|
|
|
|
## اعتبارسنجی متعلق به Form Request است
|
|
نوشتن قوانین داخل کنترلر جواب میدهد ولی مقیاس نمیشود. با Form Request اعتبارسنجی، مجوزدهی و قوانین کنار هم مینشینند و میشود جداگانه تستشان کرد.
|
|
- قوانین را به دامنهی مربوطه بچسبان.
|
|
- خطای پیشفرض ۴۲۲ را برگردان؛ بیشتر کلاینتها آن را بلدند.
|
|
- برای موارد خاص، چند rule سفارشی بنویس بهجای اینکه شرایط را در کنترلر تلنبار کنی.
|
|
|
|
## محدودسازی نرخ یک ویژگی امنیتی است، نه یک آپشن
|
|
یک مسیر عمومیِ نوشتن تا وقتی throttle نباشد طعمهی اسپم است. برای مسیر، محدودیتِ منطقی (مثلاً چند درخواست در دقیقه) بگذار و بعد ببین کلاینتهای واقعی به چه چیزی نیاز دارند.
|
|
|
|
## این وبسایت چه میکند
|
|
API وبلاگ و سایت دقیقاً همین الگو را دنبال میکنند: فرم ریکوئست برای اعتبارسنجی، JSON ریسورس برای خروجی، و throttle برای هر مسیر تا ترافیک ناشناس نتواند دیتابیس را غرق کند.
|
|
|
|
## جمعبندی
|
|
قراردادهای کوچک و خستهکننده از انتزاعهای هوشمند بهترند. شکلِ پاسخِ یکدست، اعتبارسنجی متمرکز و throttle منطقی، API را از «روی من کار میکند» به «روی همه کار میکند» میرسانند.
|
|
|
|
## نکات کلیدی
|
|
- شکل پاسخ را یکبار با API ریسورس تعریف کن تا کلاینت هیچوقت حدس نزند آبجکت است یا آرایه.
|
|
- اعتبارسنجی، مجوزدهی و قوانین را به Form Request منتقل کن تا کنار هم بمانند و جدا قابل تست باشند.
|
|
- خطای پیشفرض ۴۲۲ را برگردان، چون بیشتر کلاینتها از قبل آن را میفهمند.
|
|
- هر مسیر عمومیِ نوشتن را throttle کن و بعد عددش را با نیاز واقعی کلاینتها تنظیم کن.
|
|
- فرم تماس عمومی به محافظت بیشتری از مسیر ادمینِ احراز هویتشده نیاز دارد.
|
|
|
|
## FAQ
|
|
|
|
Q: چرا اعتبارسنجی را از کنترلر به Form Request منتقل کنیم؟
|
|
A: نوشتن قوانین داخل کنترلر تا جایی جواب میدهد که دیگر مقیاس نمیشود. Form Request اعتبارسنجی، مجوزدهی و قوانین را کنار هم نگه میدارد، اجازه میدهد جداگانه تستشان کنی و قوانین را نزدیک دامنهی خودشان نگه میدارد.
|
|
|
|
Q: چه محدودیت نرخی برای یک مسیر عمومی منطقی است؟
|
|
A: با یک عدد منطقی شروع کن، مثلاً چند تلاش در دقیقه، و بعد از اینکه دیدی کلاینتهای واقعی به چه چیزی نیاز دارند تنظیمش کن. فرم تماس عمومی به محافظت بیشتری از مسیر ادمینِ احراز هویتشده نیاز دارد، چون ترافیک ناشناس میتواند دیتابیس را غرق کند.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'استقرار بدون توقف سرویس با Docker Compose؛ راهنمای گامبهگام',
|
|
'slug' => 'zero-downtime-deployments-docker-compose-fa',
|
|
'excerpt' => 'آپدیت رولینگ، health check ها و ترتیب دقیق فلگها؛ چطور یک استک Docker Compose را بدون افتادن حتی یک درخواست بهروزرسانی کنیم.',
|
|
'category' => 'devops-fa',
|
|
'tags' => ['docker-fa', 'devops-fa'],
|
|
'cover' => 'استقرار با داکر کامپوز',
|
|
'views' => 2400,
|
|
'likes' => 210,
|
|
'days_ago' => 14,
|
|
'body' => <<<'TEXT'
|
|
# استقرار بدون توقف سرویس با Docker Compose
|
|
## هدف
|
|
راهاندازیِ مجددی که سایت را چند ثانیه آفلاین کند، استقراری است که بیسروصدا شکست خورده. با یک ریورس پراکسی جلوی سرویسها و یک health check پشت آن، میشود استک را طوری بهروزرسانی کرد که کانتینر قدیمی تا وقتی جدید آماده شود به درخواستها پاسخ دهد.
|
|
|
|
## اول health check ها
|
|
کامپوز به شما اجازه میدهد برای هر سرویس یک healthcheck تعریف کنید.
|
|
- پراکسی فقط به کانتینرهایی که «healthy» اعلام شدهاند ترافیک بدهد.
|
|
- اندپوینت سلامت فقط ۲۰۰ نباشد؛ باید اتصال به دیتابیس پشت آن را هم بررسی کند.
|
|
- برای بوت اول، start_period سخاوتمندانه بگذار.
|
|
|
|
## تاکتیک بهروزرسانی
|
|
وقتی `docker compose up -d` اجرا میکنید، کامپوز کانتینرهای تغییرکرده را یکییکی بازسازی میکند. این را کنار یک پراکسی در حال اجرا بگذارید و یک آپدیت رولینگ رایگان دارید.
|
|
- مهاجرتها و کارهای طولانی را بهعنوان سرویس جداگانهی one-shot و قبل از ریاستارت وب اجرا کن.
|
|
- بگذار کانتینر جدید قبل از حذف کانتینر قدیمی به حالت healthy برسد.
|
|
- هنگام جابهجایی لاگها را تماشا کن؛ برنامه «بگذار و برو» نیست.
|
|
|
|
## دیپلوی این وبلاگ واقعاً چه میکند
|
|
اسکریپت استقرار این سایت تصاویر جدید را میکشد، قبل از مهاجرتها یک گارد اجرا میکند، کانتینرهای جدید را بالا میآورد و بعد از آن URL سلامت میگیرد تا قبل از اعلام موفقیت، ۲۰۰ بودن را ببیند. همین قدمِ راستیآزمایی است که استقرار را از آرزو به واقعیت تبدیل میکند.
|
|
|
|
## جمعبندی
|
|
عدم توقف سرویس ترکیبی از عادتهای کوچک است: اندپوینت سلامتِ واقعی، پراکسیای که به آن احترام میگذارد و اسکریپتی که زود خوشحال نمیشود. بررسیها را خودکار کن؛ همکارانت تشکر میکنند.
|
|
|
|
## نکات کلیدی
|
|
- یک ریورس پراکسی جلوی استک بگذار و بگذار فقط به کانتینرهایی که healthy اعلام کردهاند ترافیک بدهد.
|
|
- اندپوینت سلامت را طوری بنویس که اتصال دیتابیس را بررسی کند، نه اینکه فقط ۲۰۰ برگرداند.
|
|
- مهاجرتها را بهصورت سرویس جداگانهی one-shot اجرا کن تا قبل از ریاستارت وب تمام شوند.
|
|
- برای بوت اول، start period سخاوتمندانه بگذار تا بوتهای کند کشته نشوند.
|
|
- قبل از اعلام موفقیت، ۲۰۰ بودن URL سلامت را راستیآزمایی کن و هنگام جابهجایی لاگها را تماشا کن.
|
|
|
|
## FAQ
|
|
|
|
Q: چه چیزی یک بهروزرسانی Docker Compose را بدون توقف میکند؟
|
|
A: ترکیب ریورس پراکسی و یک health check واقعی. کامپوز کانتینرهای تغییرکرده را یکییکی بازسازی میکند، پس تا وقتی پراکسی فقط به کانتینرهای healthy ترافیک بدهد، کانتینر قدیمی تا بوت شدن کانتینر جدید به درخواستها پاسخ میدهد.
|
|
|
|
Q: اندپوینت سلامت قبل از اعلام موفقیت استقرار باید چه چیزی را بررسی کند؟
|
|
A: بیشتر از یک کد وضعیت. اندپوینت باید اتصال دیتابیس پشت آن را هم بررسی کند و اسکریپت استقرار باید قبل از اعلام موفقیت، URL سلامت را بگیرد و ۲۰۰ ببیند. همین قدم راستیآزمایی است که استقرار را از آرزو به واقعیت تبدیل میکند.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'در مصاحبهی فرانتاند چه میپرسم؟ ۸ سؤالی که واقعاً عملکرد را پیشبینی میکنند',
|
|
'slug' => 'frontend-interview-questions-fa',
|
|
'excerpt' => 'سؤالهایی که واقعاً در مصاحبههای فرانتاند میپرسم و به چه چیزی در هر پاسخ گوش میدهم؛ از رفتار لِیآوت تا رفتار با یک بیلد خراب.',
|
|
'category' => 'career-fa',
|
|
'tags' => ['react-fa', 'clean-code-fa', 'career-fa'],
|
|
'cover' => 'سوالات مصاحبه فرانت اند',
|
|
'views' => 3900,
|
|
'likes' => 370,
|
|
'days_ago' => 21,
|
|
'body' => <<<'TEXT'
|
|
# در مصاحبهی فرانتاند چه میپرسم؟
|
|
## چرا سؤال حفظی نمیپرسم
|
|
از حفظ گفتن اسم یک سری هوک، بلد بودنِ مرور را نشان میدهد، نه رفتار روز اول کار را. من قضاوت، مهارت دیباگ و توانایی توضیح دادنِ بدهبستانها (trade-off) را میسنجم.
|
|
|
|
## سؤالها
|
|
- بین URL و اولین پنت چه اتفاقی میافتد؟
|
|
- کی برای بارگذاری داده سراغ `useEffect` میروی و چرا معمولاً انتخابِ اشتباهی است؟
|
|
- یک کامپوننت با هر تایپ کلید re-render میشود. از کجا شروع به بررسی میکنی؟
|
|
- یک مشکل لِیآوت را با `position: absolute` حل کن. کی همین کار اشتباه بود؟
|
|
- چطور یک کامپوننت کلاس قدیمی را بدون شکستن اپ مهاجرت میدهی؟
|
|
- `npm ci` روی CI خراب است ولی محلی کار میکند. اول کجا را نگاه میکنی؟
|
|
- تفاوت LCP و TTFB را برای یک مدیر محصول توضیح بده.
|
|
- آخرین بار چه موقع چیزی را منتشر کردی که ازش خجالت میکشیدی؟
|
|
|
|
## به چه چیزی گوش میدهم
|
|
- اسم بردن از مراحل واقعی مرورگر از نقلقول مستندات بهتر است.
|
|
- «بسته به شرایط» گفتن و بعد نام بردنِ همان شرایط، برای من مطلوبترین جواب است.
|
|
- اعتمادبهنفس در دیباگ از جوابِ اولِ بینقص مهمتر است؛ میخواهم فرایند فکر بشنوم، نه حدس درست.
|
|
|
|
## جمعبندی
|
|
مصاحبه باید شغل را شبیهسازی کند: بدهبستان، دیباگ و ارتباط شفاف. سؤالهایی که اینها را پاداش میدهند، آن مهندسانی را پیدا میکنند که واقعاً تحویل میدهند.
|
|
|
|
## نکات کلیدی
|
|
- سؤالهای حفظی را کنار بگذار و بهجایش قضاوت، مهارت دیباگ و توان توضیح بدهبستانها را بسنج.
|
|
- سؤالهایی بپرس که شبیه شغل واقعیاند، از اتفاقات بین URL تا اولین پنت تا خرابی npm ci.
|
|
- کسی را ترجیح بده که مراحل واقعی مرورگر را نام ببرد، نه اینکه از مستندات نقلقول کند.
|
|
- «بسته به شرایط» گفتن و بعد نام بردنِ همان شرایط را نشانهی قوی بدان.
|
|
- اعتمادبهنفس در دیباگ و روشن بودن مسیر فکر را از یک جواب اولِ بینقص مهمتر بدان.
|
|
|
|
## FAQ
|
|
|
|
Q: چرا دیگر سؤالهایی مثل «کدام هوکها وجود دارند» نمیپرسم؟
|
|
A: حفظ کردن اسم هوکها فقط نشان میدهد کسی بلد است حفظ کند، نه اینکه روز اول کارش چطور خواهد بود. سؤالهای مهم قضاوت، مهارت دیباگ و توان توضیح بدهبستانها را میسنجند، چون کار واقعاً همینها را میخواهد.
|
|
|
|
Q: وقتی داوطلب گیر میکند، جواب قوی چه شکلی است؟
|
|
A: میخواهم فرایند فکرش را بشنوم، نه اینکه حدسش درست بوده یا نه. نام بردن از مراحل واقعی مرورگر بهتر از نقلقول مستندات است، و «بسته به شرایط» گفتن و بعد نام بردن همان شرایط، مطلوبترین جواب از نظر من است.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'سرور کامپوننتها در برابر کلاینت کامپوننتها؛ کدام را کی استفاده کنیم؟',
|
|
'slug' => 'react-server-vs-client-components-fa',
|
|
'excerpt' => 'مدل ذهنی مرز سرور و کلاینت در ریاکت مدرن، با مثالهای مشخص از اینکه کدام طرف چه چیزی را باید ببیند — و نکست واقعاً چه چیزی را تدوین میکند.',
|
|
'category' => 'react-nextjs-fa',
|
|
'tags' => ['react-fa', 'nextjs-fa'],
|
|
'cover' => 'سرور کامپوننت در ریاکت',
|
|
'views' => 2800,
|
|
'likes' => 250,
|
|
'days_ago' => 30,
|
|
'body' => <<<'TEXT'
|
|
# سرور کامپوننتها در برابر کلاینت کامپوننتها
|
|
## مدل ذهنی در یک جمله
|
|
سرور کامپوننت جایی رندر میشود که دادهی تو آنجاست؛ کلاینت کامپوننت جایی که کاربرِ توست. بقیهی ماجرا از همین یک جمله بیرون میآید.
|
|
|
|
## سرور کامپوننت چه چیزهایی میدهد
|
|
- دسترسی مستقیم به دیتابیس و فایلسیستم بدون یک API جداگانه.
|
|
- صفر جاواسکریپت زمان اجرا برای بخشهایی که فقط محتوا نمایش میدهند.
|
|
- باندل کوچکتر، چون کتابخانههایی که سمت سرور استفاده میشوند هرگز به مرورگر نمیرسند.
|
|
|
|
## چه چیزی شما را مجبور به کلاینت کامپوننت میکند
|
|
- State و افکت: `useState`، `useEffect`، هندلر رویداد.
|
|
- APIهای مرورگر: geometry، media query، storage.
|
|
- Context و تعاملهایی که کاربر باید فوراً حس کند.
|
|
|
|
## قسمت سخت وسط
|
|
پراپهایی که از سرور کامپوننت رد میشوند دادهی سریالشدهاند؛ پس شگفتی در مرز کمین کرده است.
|
|
- تابعها و instance های کلاس از این مرز عبور نمیکنند.
|
|
- کلاینت کامپوننتها را نزدیک برگهای تعاملی نگه دار و سرور کامپوننتها را به سمت ریشههای داده ببر.
|
|
- وقتی یک کامپوننت «هر دو» است، بشکنش: یک پوستهی کلاینت و یک بدنهی سرور.
|
|
|
|
## این وبلاگ چطور سازماندهی شده
|
|
صفحهها و بدنهی پستها رندر سمت سرورند و تمتغییر و منوی موبایل جزیرههای کلاینت. همین تقسیم باعث میشود سایت تعاملی بماند ولی جاواسکریپت کمی تحویل بدهد.
|
|
|
|
## جمعبندی
|
|
بهجای «این کامپوننت هوک دارد پس کلاینت» بپرس کار باید کجا اجرا شود، بعد بقیه را بسپار به فریمورک.
|
|
|
|
## نکات کلیدی
|
|
- بپرس کار باید کجا اجرا شود: سرور کامپوننت جایی رندر میشود که داده هست، کلاینت کامپوننت جایی که کاربر.
|
|
- برگهای تعاملی را کلاینت نگه دار و سرور کامپوننتها را به سمت ریشههای داده ببر.
|
|
- پراپهایی که از مرز عبور میکنند دادهی سریالشدهاند، پس تابعها و instanceهای کلاس از آن رد نمیشوند.
|
|
- کامپوننتی که «هر دو» است را بشکن: یک پوستهی کلاینت و یک بدنهی سرور.
|
|
- بخشهای فقط نمایشی را به سرور بسپار تا برایشان صفر جاواسکریپت زمان اجرا تحویل بدهی.
|
|
|
|
## FAQ
|
|
|
|
Q: چه چیزی یک کامپوننت را به کلاینت کامپوننت تبدیل میکند؟
|
|
A: توانایی استفاده از هوک نیست، بلکه کاری است که باید انجام دهد. State و افکت، هندلر رویداد، APIهای مرورگر مثل geometry و media query و storage، و تعاملهایی که کاربر باید فوراً حس کند، کامپوننت را کلاینت میکنند.
|
|
|
|
Q: وقتی پراپ از سرور کامپوننت به کلاینت کامپوننت میفرستم، چه چیزی خراب میشود؟
|
|
A: پراپهایی که از این مرز عبور میکنند به دادهی سریالشده تبدیل میشوند و تابعها و instanceهای کلاس از آن عبور نمیکنند، پس شگفتی در همین مرز کمین میکند. کلاینت کامپوننتها را نزدیک برگهای تعاملی نگه دار و سرور کامپوننتها را به سمت ریشههای داده ببر.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'سئو تکنیکال و Core Web Vitals برای وبهای فارسی',
|
|
'slug' => 'technical-seo-persian-websites-fa',
|
|
'excerpt' => 'فارسی بودن سایت یعنی فونت سنگینتر، چیدمان راستبهچپ و هاستینگی که با CDN خارجی نمیخواند؛ اینجا میگویم چطور LCP، INP و CLS را برای وبهای فارسی درست کنم.',
|
|
'category' => 'web-performance-seo-fa',
|
|
'tags' => ['seo-fa', 'performance-fa'],
|
|
'cover' => 'چکلیست Core Web Vitals',
|
|
'views' => 1900,
|
|
'likes' => 130,
|
|
'days_ago' => 11,
|
|
'body' => <<<'TEXT'
|
|
# سئو تکنیکال و Core Web Vitals برای وبهای فارسی
|
|
|
|
هر پروژهی فارسی که تحویل میدهم با یک سؤال شروع میشود: آیا این سایت برای کاربری که فارسی میخواند و روی اینترنت موبایل ایران است، واقعاً سریع بالا میآید؟ جواب در بیشتر پروژهها خیر است. دلیلش هم در کد جاوااسکریپت نیست؛ در فونتهای وب، تصاویر قالبهای سنگین وردپرس، چیدمان راستبهچپ و محل هاستینگ است.
|
|
|
|
## چرا Core Web Vitals برای سایت فارسی متفاوت است
|
|
|
|
گوگل سه معیار Web Vitals را سیگنال رتبهبندی معرفی کرده است: LCP برای بارگذاری بصری، INP برای تعامل و CLS برای پایداری چیدمان. منطقشان جهانی است، اما ورودیهایشان در پروژهی فارسی متفاوت است. فونت فارسی چند برابر سنگینتر از لاتین است و اگر درست بارگذاری نشود، هر دو معیار اول بهشدت آسیب میبینند. نتیجه این است که یک سایت فارسی با همان کیفیت کد، امتیاز بسیار پایینتری میگیرد.
|
|
|
|
## LCP و سنگینی فونتهای وب فارسی
|
|
|
|
بزرگترین عامل مخرب LCP در سایتهای فارسی تقریباً همیشه فونت وب است. فونتهایی مثل وزیرمتن وقتی کل وزن فایل را یکجا بارگذاری میکنند، بهتنهایی چند صد کیلوبایت اضافه میکنند. اگر font-display روی swap باشد، متن ابتدا با فونت جایگزین نمایش داده میشود؛ یعنی نخستین رندر کاملاً متفاوت از چیزی است که کاربر نهایی میبیند.
|
|
|
|
کاری که من میکنم: فقط وزنهای استفادهشده را نگه میدارم، فایلها را به woff2 تبدیل میکنم، subset فارسی میگیرم و فایل اصلی را preload میکنم. در وردپرس این کار را در فونتهای خود قالب انجام میدهم، نه با پلاگین اضافه. نتیجه معمولاً انتقال LCP از محدودهی قرمز به زرد یا سبز است.
|
|
|
|
## تصویر قالبهای سنگین وردپرس
|
|
|
|
در وردپرس، قالب قطورترین منبع مشکل است: اسلایدر چندتصویری، فونت آیکون اضافه، فونت فارسی تکراری و تصاویر بدون ابعاد مشخص، همه با هم جمع میشوند. من اول با Coverage و Network در Chrome DevTools میبینم کدام درخواستها طولانی و کدامها بیاستفادهاند. معمولاً دو یا سه فایل، هفتاد درصد مشکل را میسازند و حذف همانها بیشتر از هر پلاگین کش اثر میگذارد.
|
|
|
|
برای تصاویر قاعدهی سادهای دارم: AVIF یا WebP با ابعاد صریح، و lazy-load برای هر چیزی که در نمای اول نیست. تصویر LCP را هرگز lazy نمیکنم.
|
|
|
|
## INP و تعامل کاربر فارسی
|
|
|
|
INP در سایتهای فارسی بیشتر از آنکه به کد مربوط باشد، به رفتار کاربر مربوط است: کاربر روی موبایل و با اینترنت موبایل اسکرول میکند و منوی چندسطحی را باز میکند. هر منوی همبرگری با جاوااسکریپت سنگین پشتش، یک کاندید INP بد است. من کارهای سنگین را به رویدادهای خاص منتقل و انیمیشنها را به transform محدود میکنم.
|
|
|
|
## CLS و جابهجایی فونت فارسی
|
|
|
|
جابهجایی محتوا، آزاردهندهترین مشکل ظاهری سایتهای فارسی است و علتش را دقیقاً میدانم: فونت وب با تأخیر میرسد و چون ارتفاع خط در فارسی با فونت جایگزین فرق محسوسی دارد، کل محتوای صفحه بالا و پایین میپرد. راهحل اول، قلم و خط ارتفاع دقیق متناسب با فونت فارسی است؛ دوم، preload فایل اصلی فونت؛ و سوم، رزرو فضا برای تصاویر و اسکلتبندی بلوکهای اصلی.
|
|
|
|
## RTL، چیدمان و ریسکهای بومیسازی
|
|
|
|
راستبهچپ فقط یک ویژگی ظاهری نیست. انیمیشن اسلاید باید از راست به چپ حرکت کند، آیکونهای جهتدار باید آینه شوند و فاصلهها را نباید دستی با left و right نوشت. تست نهایی را همیشه روی مرورگر واقعی موبایل انجام میدهم، چون بیشتر باگهای بومیسازی روی دسکتاپ پیدا نمیشوند.
|
|
|
|
## هاستینگ، کاربران داخلی و مسئلهی CDN
|
|
|
|
این نکتهای است که در مقالههای انگلیسی کمتر دربارهاش صحبت میشود. یک CDN خارجی برای کاربر داخل ایران میتواند حتی کندتر باشد، چون مسیر برگشت داده از کاربر ایرانی تا نقطهی لبهی خارجی طولانی و پر از گره است. برای مخاطب ایرانی، هاستینگ یا CDN داخلی معمولاً نتیجهی واقعی بهتری میدهد، حتی اگر در تست بینالمللی ضعیفتر باشد.
|
|
|
|
در عمل من ترکیبی تصمیم میگیرم: سرور نزدیک به مخاطب اصلی، کش سمت سرور، و CDN برای فایلهای استاتیک وقتی مخاطب بینالمللی است. بودجهی مشتری ایرانی محدود است و باید صرف جایی شود که نتیجهی قابل اندازهگیری دارد.
|
|
|
|
## گوگل دیسکاور و معنی واقعی سئو تکنیکال
|
|
|
|
سئو تکنیکال در نهایت یک هدف دارد: ایمکان خزش و ایندکس. در سایتهای فارسی سه مورد را بیش از حد دستکم میگیریم. اول، استفاده از «ي» عربی بهجای «ی» فارسی که دو نسخهی متفاوت از یک آدرس ایندکس میکند. دوم، لینکهای داخلی به آدرسهای پارامتردار که بینهایت نسخه میسازند. سوم، دادهی ساختاریافتهی نامناسب. اینها را قبل از هر بهینهسازی سرعتی حل میکنم، چون اگر صفحه ایندکس نشود، سریع بودنش بیفایده است.
|
|
|
|
## چکلیست عملی که برای هر پروژه اجرا میکنم
|
|
|
|
- فونت وب فارسی را به woff2 تبدیل و به وزنهای استفادهشده محدود کنید.
|
|
- فایل فونت اصلی را preload و font-display را روی swap بگذارید.
|
|
- تصویر LCP را بدون lazy و با فرمت مدرن بارگذاری کنید.
|
|
- اندازهی قلم و خط ارتفاع را برای فونت فارسی تنظیم کنید تا CLS حذف شود.
|
|
- جاوااسکریپتهای غیرضروری قالب وردپرس را حذف یا defer کنید.
|
|
- کش سمت سرور را فعال و فایلهای استاتیک را با طولانیترین عمر کش کنید.
|
|
- هاستینگ را متناسب با محل مخاطب انتخاب کنید، نه فقط بر اساس قیمت.
|
|
- مسیرها را یکسانسازی کنید تا «ي» و «ی» دو آدرس متفاوت نسازند.
|
|
- دادهی ساختاریافته و متادیتای بومیسازیشده را بررسی کنید.
|
|
- نتایج را در Search Console و PageSpeed Insights ثبت کنید.
|
|
|
|
## جمعبندی
|
|
|
|
سئو تکنیکال برای وبهای فارسی، بیش از آنکه کار فنی باشد، مجموعهای از تصمیمهای آگاهانه دربارهی متن و زبان است. وقتی فونت را سبک میکنید، محل سرور را با مخاطب هماهنگ میکنید و چیدمان راستبهچپ را جدی میگیرید، Core Web Vitals خودبهخود بهتر میشوند.
|
|
|
|
## نکات کلیدی
|
|
- یک خانوادهی فونت فارسی، حداکثر دو وزن، با woff2، subset و preload؛ بزرگترین عامل مخرب LCP همین است.
|
|
- تصویر LCP را هرگز lazy نکنید؛ AVIF یا WebP با ابعاد صریح بدهید و بقیهی تصاویر را lazy کنید.
|
|
- ارتفاع خط را با متن فارسی واقعی تنظیم کنید، وگرنه پرش محتوا و CLS باقی میماند.
|
|
- قبل از هر بهینهسازی سرعت، مشکل ایندکس را حل کنید: «ي» عربی، لینکهای پارامتردار و دادهی ساختاریافتهی نامناسب.
|
|
- هاستینگ یا CDN داخلی برای مخاطب ایرانی معمولاً نتیجهی واقعی بهتری میدهد، حتی اگر در تست بینالمللی ضعیفتر باشد.
|
|
|
|
## FAQ
|
|
|
|
Q: سایت فارسی من امتیاز پایینی دارد؛ از کجا شروع کنم؟
|
|
A: در بیشتر پروژهها مشکل از فونت وب فارسی است، نه از کد. وزنهای استفادهنشده را حذف کنید، فایلها را به woff2 تبدیل و subset فارسی بگیرید و فایل اصلی را preload کنید.
|
|
|
|
Q: چرا محتوای سایت بعد از بارگذاری بالا و پایین میپرد؟
|
|
A: چون فونت وب با تأخیر میرسد و ارتفاع خط در فارسی با فونت جایگزین فرق محسوسی دارد. راهحل، خط ارتفاع دقیق برای فونت فارسی، preload فایل اصلی و رزرو فضا برای تصاویر و بلوکهای اصلی است.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'فریلنسری و دورکاری برنامهنویسان ایرانی؛ راهنمای عملی',
|
|
'slug' => 'iranian-developers-freelancing-remote-fa',
|
|
'excerpt' => 'از نمونهکار و پوزیشننگ تا اولین مشتری خارجی، انتقال وجه و قرارداد؛ نقشهی راه عملی فریلنسری برای توسعهدهندهای که از ایران کار میکند.',
|
|
'category' => 'career-fa',
|
|
'tags' => ['freelancing-fa', 'career-fa'],
|
|
'cover' => 'راهنمای فریلنسری دورکاری',
|
|
'views' => 2200,
|
|
'likes' => 160,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# فریلنسری و دورکاری برنامهنویسان ایرانی؛ راهنمای عملی
|
|
|
|
هر پروژهای که در سالهای اخیر پذیرفتهام، یک سؤال اول داشته: «از کجا مطمئن شوم خوب کار میکنی؟» پاسخ من هیچوقت رزومهی چند صفحهای نبود؛ همیشه نمونهکار بود. اگر میخواهید بهعنوان یک برنامهنویس ایرانی وارد بازار فریلنسری و دورکاری شوید، این نوشته خلاصهی همان چیزی است که در عمل یاد گرفتهام.
|
|
|
|
## واقعیت بازار: داخل ایران و خارج از ایران
|
|
|
|
بازار داخلی برای شروع سریعتر است و پرداختها قابل پیشبینیتر. اما سقف نرخ ساعتی پایین است و بیشتر پروژهها یا با چانهزنی شدید پیش میروند یا پشتیبانی ماهانهی مبهمی دارند. بازار خارجی نرخ بهمراتب بهتری دارد، اما رقابت شدیدتر است.
|
|
|
|
راهبردی که پیشنهاد میکنم: نیمی از انرژیتان روی پایهای قابل اتکا در بازار داخلی تا جریان نقدی قطعی داشته باشید، و نیم دیگر صرف رزومهی بینالمللی و پروژههای با نرخ بالاتر شود.
|
|
|
|
## پوزیشننگ مهمتر از رزومه است
|
|
|
|
در فریلنسری، کارفرما یک جمله میخواهد: دقیقاً چه کاری برای چه کسی انجام میدهید. «برنامهنویس React و Next.js» یک مهارت است، نه یک جایگاه. «تبدیل رابط ادمین قدیمی یک شرکت لجستیکی به داشبورد Next.js سریع، با کاهش زمان بارگذاری صفحات از چهار ثانیه به یک ثانیه» یک جایگاه است. دومی در رقابت بر سر نرخ برنده است، چون نتیجهی قابل اندازهگیری دارد.
|
|
|
|
توصیهی عملی من: برای هر حوزهای که میتوانم اثبات کنم، یک جملهی روشن بنویسم و همان را در پروفایل، رزومه و پیامهای اولیه تکرار کنم.
|
|
|
|
## نمونهکار عمومی بسازید، حتی اگر مشتری ندارید
|
|
|
|
بزرگترین مانع شروع، نداشتن سابقه است. راهحلش ساختن سه نوع نمونهکار است، نه سه نوع رزومه.
|
|
|
|
نمونهکار اول، مخزن گیتهاب است: پروژهای واقعی که خودم از صفر نوشتهام، با README درست، تست و کامیتهای منظم. برای کارفرمای فنی، گیتهاب معادل نمونهکار است چون روند کار را نشان میدهد.
|
|
|
|
نمونهکار دوم، مقالهی فنی است دربارهی همان چیزی که در آن قویام: تجربهی واقعی از یک مشکل واقعی، با توضیح تصمیمهایی که گرفتهام.
|
|
|
|
نمونهکار سوم، یک پروژهی زنده است؛ ابزاری کوچک که همین حالا کار میکند و کسی میتواند امتحانش کند. ساختن این سه مورد چند هفته وقت میگیرد و مسیر اولین مشتری را چند ماه کوتاه میکند. هیچ پروژهای را که مجاز به انتشار نیست، بدون دمو در پروفایل نمیآورم؛ ویدئوی کوتاهی از دموی محلی جای خالی نمونهکار را پر میکند.
|
|
|
|
## چطور اولین مشتری خارجی را بگیریم
|
|
|
|
پس از آماده کردن نمونهکارها، ترتیب مشخصی را دنبال میکنم. اول، شبکهی حرفهای موجودم: همکاران سابق، همکلاسیها و آدمهای جامعهی توسعه. دوم، در پلتفرمهای بینالمللی بهجای صدها پیشنهاد عمومی، ده پیشنهاد شخصی مینویسم که مشکل واقعی کارفرما را نام میبرد. سوم، در انجمنهای تخصصی به سؤالها پاسخ دقیق و کوتاه میدهم. این سه مسیر کیفیت مشتری را بالا میبرد.
|
|
|
|
در نوشتن پیشنهاد همیشه سه چیز میآورم: فهم مسئله، روی پیشنهادم، و یک سؤال واقعی دربارهی محدودیتها. سؤال واقعی نشان میدهد قبل از اعلام قیمت فکر کردهام.
|
|
|
|
## انتقال وجه: بخشی که کمتر دربارهاش صحبت میشود
|
|
|
|
این بخش عملیترین قسمت کار من است و کمترین مستندات را دارد. من فقط از مسیرهای قانونی و شفاف استفاده میکنم؛ یعنی پرهیز از انتقالهای ناشناس، حسابهای جعلی و روشهایی که جوابی برای شما ندارند.
|
|
|
|
برای مشتری خارجی دو حالت دارم. حالت اول، قرارداد مستقیم با خود کارفرما است و پرداخت روی پلتفرمی انجام میشود که خود کارفرما از آن استفاده میکند؛ مسیر انتقال بر عهدهی اوست و من فقط مسئول دریافت سرویس هستم. حالت دوم، پلتفرمهای واسطهای که انتقال را با کمیسیون و در چارچوب رسمی خود انجام میدهند؛ هزینهی بیشترش را میپذیرم، چون در ایران قابل پیگیری است. در بازار داخلی هم قرارداد مکتوب و پیشپرداخت مرحلهای برای من غیرقابل مذاکره است.
|
|
|
|
## قرارداد و اسکوپ؛ مهمترین بخش کاری
|
|
|
|
بیشتر پروژههای فریلنسری که خراب میشوند بهخاطر ضعف فنی نیستند؛ بهخاطر ابهام در اسکوپاند. قبل از شروع مکتوب میکنم: خروجی دقیق، تعداد اصلاحات مجاز، معیار پذیرش، زمانبندی مرحلهای و نحوهی مدیریت درخواستهای خارج از اسکوپ. جملهای که همیشه میگویم این است: «هر درخواستی که در سند اسکوپ نیست، یا زمان اضافه میخواهد یا هزینهی اضافه.» بدون آن، دامنهی پروژه باز میماند و پروژه هرگز تمام نمیشود.
|
|
|
|
## تفاوت ساعت کاری و فرهنگ کاری
|
|
|
|
ساعت کاری شما با بازار خارجی همپوشانی کامل ندارد. بهجای جنگیدن با این واقعیت، آن را مدیریت کنید. من بلوکهای کاری مشخصی برای همکاری زنده با تیم غربی میگذارم و کارهای تمرکزی را به ساعات پربازده منتقل میکنم. در جلسات هم صریح میگویم کِی در دسترسام.
|
|
|
|
فرهنگ کاری هم تفاوت دارد. برای تیمهای خارجی، مستندسازی و اعلام زودهنگام مشکل بخشی از کار است نه مزاحمت. توانایی نوشتن انگلیسی فنی، در عمل بیشتر از هر مهارت دیگری نرخ شما را جابهجا میکند.
|
|
|
|
## از کلاهبرداری چطور دور بمانیم
|
|
|
|
چند قاعدهی ساده که بعد از چند ضرر یاد گرفتهام. هیچ پروژهای را بدون پیشپرداخت شروع نمیکنم؛ اگر کارفرما روی پرداخت کل مبلغ اصرار دارد، همانجا پروژه رد است. درخواست ساخت یک برنامهی کامل و بدون پیشپرداخت بهنام کارفرما تقریباً همیشه نشانهی بدی است.
|
|
|
|
درخواست اتصال به حساب، دسترسی بیدلیل به سرور یا برگرداندن پول بعد از انجام کار را هم رد میکنم. جلسهی تصویری کوتاه با تیم مدیریت، اعتماد را بهشکل معناداری بالا میبرد. پورتفولیوی من بدون رضایت مشتری محرمانه منتشر نمیشود.
|
|
|
|
## چند توصیهی پایانی
|
|
|
|
سرعت یادگیری فنی را کند نکنید، چون نرخ شما تقریباً مستقیم به مهارتی است که شش ماه پیش داشتهاید. روی مهارتی سرمایهگذاری کنید که تقاضا دارد و رقابت در آن کم است. و ساعتی از خود را برای دارایی بلندمدت کنار بگذارید؛ محصول، ابزار یا دورهای که مال خودتان باشد، روزی سیستم کارفرمایی شما میشود.
|
|
|
|
## نکات کلیدی
|
|
- نرخ ساعتی اهرم نیست؛ روی نتیجهی قابل اندازهگیری با عدد تمرکز کنید، چون شواهد همیشه از کارت نرخ برنده میشود.
|
|
- سه نوع نمونهکار عمومی بسازید: مخزن گیتهاب، مقالهی فنی و یک پروژهی زنده.
|
|
- هر درخواستی خارج از اسکوپ را جداگانه قیمتگذاری کنید؛ بدون این کار دامنهی پروژه باز میماند و پروژه هرگز تمام نمیشود.
|
|
- هیچ پروژهای را بدون قرارداد مکتوب و پیشپرداخت مرحلهای شروع نکنید و فقط از مسیرهای قانونی و شفاف استفاده کنید.
|
|
- انگلیسی فنی، در عمل بیشتر از هر مهارت دیگری نرخ شما را جابهجا میکند.
|
|
|
|
## FAQ
|
|
|
|
Q: از کجا شروع کنم وقتی سابقهی فریلنسری ندارم؟
|
|
A: راهحل نداشتن سابقه، ساختن سه نوع نمونهکار است، نه سه نوع رزومه: یک مخزن گیتهاب واقعی، یک مقالهی فنی دربارهی همان چیزی که در آن قوی هستید، و یک پروژهی زنده که همین حالا کار میکند و کسی میتواند امتحانش کند.
|
|
|
|
Q: از کلاهبرداری چطور دور بمانم؟
|
|
A: پرچمهای قرمز ثابتاند: پروژهی مبهم، بودجهی غیرقابلباور، رد کردن تماس تصویری یا درخواست واریز وجه برای فعالسازی پلتفرم. هویت را تأیید کنید و هرگز به نشانی دیکتهشده در تماس تلفنی پول نفرستید.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'هوش مصنوعی و آیندهی شغلی برنامهنویسی در ایران',
|
|
'slug' => 'ai-coding-careers-iran-fa',
|
|
'excerpt' => 'یک ارزیابی واقعبینانه از ۲۰۲۶: هوش مصنوعی کدام کارها را گرفته، کدامها هنوز انسانی مانده و چرا تهدید واقعی، عقبماندن از آن است نه خودِ هوش مصنوعی.',
|
|
'category' => 'career-fa',
|
|
'tags' => ['ai-fa', 'career-fa'],
|
|
'cover' => 'آیندهی شغلی و هوش مصنوعی',
|
|
'views' => 2000,
|
|
'likes' => 145,
|
|
'days_ago' => 6,
|
|
'body' => <<<'TEXT'
|
|
# هوش مصنوعی و آیندهی شغلی برنامهنویسی در ایران
|
|
|
|
وقتای کدنویسی جدید رونق گرفت، بازار پر شد از جملههایی مثل «برنامهنویسی شغل قرن است» و «هوش مصنوعی همه را بیکار میکند». هیچکدام دقیق نبود. تجربهی من در تیمهای محصولی، هم فنی و هم از دید بازار کار ایران، این است که تهدید واقعی نه خودِ هوش مصنوعی بلکه فاصلهی ما از آن است.
|
|
|
|
## تصویر واقعبینانه از سال ۲۰۲۶
|
|
|
|
من هر هفته با هوش مصنوعی کار میکنم و تجربهی روزمرهام این است: بخش بزرگی از کدی که قبلاً مینوشتم، الان در چند ثانیه تولید میشود. یک کامپوننت ساده، اسکوئری تکراری، یک تست؛ همهی اینها کار شدند و زمان تحویل کارهای تکراری نصف شده است.
|
|
|
|
اما همان تجربه یک نکتهی دیگر هم نشان میدهد. بیشترین زمان ما در کدنویسی صرف فکر کردن، فهمیدن اینکه کدام راهحل با معماری فعلی جور است، و دیباگ کردن میشود. هوش مصنوعی اینجا کمک میکند اما جای شما را نمیگیرد. جایی که کد تولید میشود ارزش کم است؛ جایی که تصمیم گرفته میشود ارزش بالاست.
|
|
|
|
## چه کارهایی را بهتر به هوش مصنوعی بسپاریم
|
|
|
|
انتخاب هوشمندانهی ابزار، مهمترین مهارتی است که در یک سال گذشته کسب کردم. کارها را به چهار دسته تقسیم میکنم. دستهی اول، کار تکراری و کمریسک؛ تستها، کد تکراری، اسکریپتهای یکبارمصرف و مستندات ساده. اینها را کامل به هوش مصنوعی میسپارم و فقط خروجی را مرور میکنم. دستهی دوم، کد یکنواخت و زیادتکرار، مثل مدلها و کامپوننتهای فرم. دستهی سوم، کد حساس که به امنیت، پرداخت یا دادهی واقعی مربوط است؛ اینجا هوش مصنوعی پیشنویس مینویسد و من بازبینی میکنم. دستهی چهارم، معماری و حل مسئلهی محصول است؛ کاملاً خودم انجام میدهم. این تقسیمبندی باعث میشود هوش مصنوعی ابزار شود، نه جایگزین.
|
|
|
|
## چه چیزی انسانی میماند
|
|
|
|
چند حوزه هست که با وجود هر پیشرفتی انسانی ماندهاند. اول، فهم محصول: کاربر ایرانی چه میخواهد، چه محدودیتهایی دارد، کجا اشکال میکند و چرا. این دانش در هیچ مدل زبانی نیست و از مصاحبه با کاربر بهدست میآید. دوم، دیباگ و ریشهیابی مسئلههای پیچیده در محیط واقعی؛ وقتی سیستمی در production خراب میشود، کسی باید از نشانهها تا علت اصلی را دنبال کند. سوم، معماری و تصمیمهای بلندمدت که هزینهی اشتباه در آنها شش ماه بعد معلوم میشود. چهارم، کار با تیم: مربیگری، کد ریویو و رشد دادن تازهکارها. پنجم، مسئولیت اخلاقی و امنیتی.
|
|
|
|
## چرا انگلیسی و مبانی، حالا مهمتر از همیشه
|
|
|
|
وقتی بخش زیادی از کار روزمره تعامل با هوش مصنوعی است، کسی که انگلیسی خوبی دارد به ابزارها، مدلها و مستندات گستردهتری دسترسی پیدا میکند. اما انگلیسی تنها مزیت نیست. مبانی، یعنی درک شبکه، سیستمعامل، ساختار داده و معماری، همان چیزی است که مرز بین یک کاربر ابزار و یک مهندس واقعی را میکشد. مدلها کد تولید میکنند، اما نمیتوانند تشخیص دهند این کد در مقیاس یک سرویس واقعی چه رفتاری خواهد داشت؛ و این تشخیص از دانش بنیادی میآید. تفاوت یک توسعهدهندهی سطح متوسط با یک توسعهدهندهی ارشد تقریباً همیشه در همین مبانی و توانایی تشخیص ریشهی مسئله است، نه در تعداد فریمورکهایی که میشناسد.
|
|
|
|
## چطور در بازار کار ایران جای خود را محکم کنیم
|
|
|
|
بازار کار ایران ویژگیهای خودش را دارد. هم نرخها پایینتر است و هم انتظارات متفاوت؛ کارفرما معمولاً همزمان چند نقش را از یک نفر میخواهد، یعنی اگر فقط در یک حوزهی باریک قوی باشید آسیبپذیرید. سه مسیر عملی میبینم. مسیر اول، تخصص عمیق در یک حوزهی ارزشمند مثل زیرساخت، داده یا امنیت. مسیر دوم، مهندسی کامل از فرانت تا بکاند که در تیمهای کوچک ایرانی بسیار تقاضا دارد. مسیر سوم، ساختن محصول بهجای فروش ساعت؛ ریسک بیشتری دارد اما هوش مصنوعی در آن بیشترین اهرم را به شما میدهد.
|
|
|
|
در هر سه مسیر، آنچه تمایز میکند، استفاده از هوش مصنوعی برای بالا بردن بازدهی خودتان است.
|
|
|
|
## چطور در رزومه و مصاحبه قوی باشیم
|
|
|
|
اگر الان برای شغل برنامهنویسی درخواست میدهید، سه چیز را در رزومه برجسته کنید. اول، تجربهی واقعی که با هوش مصنوعی در بهرهوری داشتهاید؛ مثلاً کاهش زمان ساخت یک ماژول از چند روز به چند ساعت، با ذکر اینکه خودتان چه تصمیمی گرفتهاید. دوم، نمونهکاری که نشان دهد مسئله را فهمیدهاید نه فقط کد زدهاید. سوم، توانایی کار ریویو و ارائهی فنی که در مصاحبه وزن زیادی دارد.
|
|
|
|
در مصاحبه هم آماده باشید که میپرسند چطور از هوش مصنوعی استفاده میکنید. پاسخ خوب، نشان دادن یک فرآیند است: اول مسئله را تحلیل میکنم، بعد پیشنویس میگیرم و سپس با تست و بازبینی خودم تأیید میکنم.
|
|
|
|
## توصیهی ویژه به تازهکارها
|
|
|
|
تازهکارها بیشترین آسیب را میبینند، چون کارهایی که قبلاً پلهی اول شغل بود، مثل نوشتن اولین نسخهی یک CRUD ساده، خودکار شدهاند. راهحل این نیست که از ابزار استفاده نکنید؛ دقیقاً برعکس. با هوش مصنوعی آزمایش کنید، شکست بخورید، دیباگ کنید و بفهمید چرا کدی که ساخته شده کار نمیکند. همان تجربهی دیباگ چیزی است که در سه سال اول کار حرفهای به شما میدهد، فقط در شش ماه.
|
|
|
|
## تهدید واقعی چیست
|
|
|
|
جمعبندی من این است: هوش مصنوعی تهدید نیست، ابزاری است که تعادل بازار کار را بازتعریف میکند. کسانی که از آن استفاده میکنند و مهارت عمیق را با آن ترکیب میکنند بهره میبرند؛ کسانی که آن را نادیده میگیرند از پس نخواهند آمد. خطر اصلی از دست دادن شغل بهخاطر هوش مصنوعی نیست؛ این است که شش ماه بعد از او جلو بماند. کاری که من انجام میدهم این است: یادگیری را متوقف نمیکنم، هوش مصنوعی را در کار روزمره جا میاندازم و روی چیزی تمرکز میکنم که انسانی میماند، یعنی فهم مسئله، تصمیمگیری و مسئولیتپذیری.
|
|
|
|
## نکات کلیدی
|
|
- راستیآزمایی کد تولیدشده را به مهارت اصلی خود تبدیل کنید؛ پرامپتنویسی حداقل است، نه تخصص.
|
|
- به سمت کارهایی بروید که به قضاوت انسانی نیاز دارند: فهم محصول، دیباگ، کارایی، امنیت و معماری.
|
|
- مبانی را جدی بگیرید؛ درک شبکه، سیستمعامل، ساختار داده و معماری مرز شما را میکشد.
|
|
- در انگلیسی بنویسید؛ مستندسازی فنی هم سازوکار یادگیری است و هم منبع پروژههای جدید.
|
|
- کل زنجیره را مالک شوید: مسئله، طراحی، ساخت، استقرار، اندازهگیری و نگهداری.
|
|
|
|
## FAQ
|
|
|
|
Q: هوش مصنوعی شغل برنامهنویسی را میگیرد؟
|
|
A: تهدید اصلی از دست دادن شغل بهخاطر هوش مصنوعی نیست؛ خطر واقعی این است که شش ماه بعد از آن جلو بمانید. هوش مصنوعی بخش بزرگی از کار را ارزانتر و سریعتر میکند و ارزش بخش انسانی را بالا میبرد.
|
|
|
|
Q: تازهکارها در ایران از کجا شروع کنند؟
|
|
A: راهحل این نیست که از ابزار استفاده نکنید؛ با هوش مصنوعی آزمایش کنید، شکست بخورید و دیباگ کنید. همان تجربهی دیباگ چیزی است که در سه سال اول کار حرفهای به شما میدهد، فقط در شش ماه.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'طراحی سایت برای کسبوکارهای کوچک ایرانی؛ چه چیزی واقعاً کار میکند',
|
|
'slug' => 'web-design-iranian-businesses-fa',
|
|
'excerpt' => 'آنچه در بازسازی سایت کسبوکارهای کوچک در ایران یاد گرفتهام: یک سایت سریع، راستبهچپ و قابل اعتماد که میفروشد، بهجای بروشوری زیبا که روی موبایل کسی بازش نمیکند.',
|
|
'category' => 'frontend-fa',
|
|
'tags' => ['design-fa', 'performance-fa'],
|
|
'cover' => 'وبسایت سریع برای کسبوکارهای کوچک',
|
|
'views' => 1800,
|
|
'likes' => 125,
|
|
'days_ago' => 14,
|
|
'body' => <<<'TEXT'
|
|
# طراحی سایت برای کسبوکارهای کوچک ایرانی؛ چه چیزی واقعاً کار میکند
|
|
|
|
بیشتر سایت کسبوکارهای کوچک ایران را کسی ساخته که هفتهی پیش وقت آزاد داشته، روی یک قالب آماده، و بعد کسی دست نزده است. الگو ثابت است: مالک کسبوکار مشتری بیشتری میخواهد و سایت به او یک اسلایدشو تحویل میدهد. این است آنچه در بازسازی این سایتها جواب داده و آنچه آگاهانه کنار میگذارم.
|
|
|
|
## آنچه تقریباً همهی آنها اشتباه میکنند
|
|
|
|
- سایت بروشوری. یک تصویر قهرمان، یک پاراگراف «دربارهی ما» از سال ۲۰۱۷، فرم تماسی که هیچکس پاسخ نمیدهد و هیچ راهی برای خرید یا رزرو. برای تزئین و چاپ روی کارت ویزیت ساخته شده است.
|
|
- اسلایدر قهرمان. سه تا پنج بنر چرخان که هر چهار ثانیه محو میشوند، هر کدام با یک تیتر فارسی غولپیکر و سایه. روی گوشی اندروید میانرده همین دلیل اصلی حس کندی صفحه است و هیچکس منتظر نمیماند.
|
|
- فونتهای حجیم. بارگذاری همزمان وزیرمتن، استعداد، صمیم، ایرانسنس و یک فونت مخصوص ارقام فارسی، آن هم در چند وزن. فونتهای وب فارسی حجیماند و بستهی اینترنت موبایل ایران آنقدر که مردم فکر میکنند نامحدود نیست.
|
|
- دسکتاپمحور بودن. طراحی در عرض ۱۴۴۰ پیکسل و بعد فشردهکردن آن. منو به یک همبرگری شکسته جمع میشود و شمارهی تلفن در فوتری کوچک گم میشود که هیچکس لمسش نمیکند.
|
|
- نبودن سیگنال اعتماد. یک لوگوی غیررسمی، بدون آدرس، مجوز و نظر مشتری.
|
|
|
|
## این سایتها واقعاً به چه چیزی نیاز دارند
|
|
|
|
با یک چیدمان موبایلمحور و راستبهچپِ شفاف شروع کنید. بیشتر ترافیک از اندرویدِ میانرده میآید و کاربر از بیوی اینستاگرام یا یک کانال تلگرام وارد میشود. یعنی: متن راستچین، `dir="rtl"` روی سند، یک نوار پایین چسبان با دکمهی تماس و واتساپ، و دقیقاً یک اقدام روشن در هر صفحه. ترتیب خواندن باید با همان شکلی باشد که متن فارسی واقعاً خوانده میشود.
|
|
|
|
تایپوگرافی فارسی بدون سنگینی سادهتر از چیزی است که مردم فکر میکنند. یک فایل فونت متغیر، دو یا سه وزن، `font-display: swap` و میزبانی روی سرور خودتان؛ همین و بس. متن اصلی با اندازهی ۱۶ تا ۱۷ پیکسل و ارتفاع خط نزدیک ۱.۹، چون فارسی به فضای عمودی بیشتری از لاتین نیاز دارد. قیمتها را با ارقام لاتین نگه دارید تا مردم بتوانند مقایسه کنند، ولی تاریخ و تلفن را همانطوری بنویسید که مشتریانتان انتظار دارند.
|
|
|
|
سرعت اینجا خودش سیگنال اعتماد است. هدف من LCP زیر ۲.۵ ثانیه و ترجیحاً زیر ۱.۸ ثانیه است، اندازهگیریشده روی یک اتصال موبایل ایرانی محدود که تأخیرش اغلب ۶۰ تا ۱۲۰ میلیثانیه است. یعنی یک تصویر قهرمان با اندازهی درست در AVIF یا WebP با ابعاد مشخص، بدون CSS مسدودکنندهی رندر، بدون کتابخانهی اسلایدر و لیزیلودینگ زیر صفحهی اول.
|
|
|
|
آنچه کاربر را به مشتری تبدیل میکند عناصر اعتماد است و اینها سادهانند: آدرس واقعی کوچه با نقشه، پروانهی کسبوکار و نشان «نماد اعتماد» اگر دارید، تلفنی که یک آدم جواب میدهد، واتساپ با پیام از پیش نوشتهشده، ساعت کاری با توضیح اینکه هفتهی ایران از شنبه تا پنجشنبه است، و نظر مشتری واقعی با نام و تاریخ. برای نقشه از نشان یا مپیر استفاده کنید، چون گوگل روی بیشتر شبکههای ایران فیلتر است. آدرس را متن ساده هم نگه دارید تا در هر اپی قابل کپی باشد.
|
|
|
|
## فروشی که روی گوشی ایرانی جواب میدهد
|
|
|
|
بیشتر این کسبوکارها به یک کاتالوگ نیاز دارند، نه یک پلتفرم پرداخت. یک شبکهی محصول یا خدمات، با یک عکس، یک قیمت و یک دکمهی واتساپ که پیامی با نام محصول از پیش نوشتهشده باز میکند. این بهتر از سبد خرید جواب میدهد، چون خریدار سفارشش را داخل همان اپی که در آن است نهایی میکند.
|
|
|
|
اگر مشتریهایتان روی بستههای محدود یا وایفای ضعیف هستند، بهجای فرم رزروی چندمرحلهای بنویسید «تماس بگیرید و رزرو کنید». بستهی محدود یعنی تصمیم کمتر.
|
|
|
|
## چکلیست بازسازی
|
|
|
|
- سایت فعلی را کراول کنید و قبل از هر تغییری، ترافیک، صفحات فرود اصلی و همهی آدرسهای ایندکسشده را ثبت کنید.
|
|
- هر آدرسی که ترافیک دارد را نگه دارید و بقیه را با ۳۰۱ به نزدیکترین معادل بفرستید.
|
|
- اسلایدرها، اسلایدشوها و هر افزونهای که تنها کارش انیمیشن است را حذف کنید.
|
|
- به یک فونت فارسی متغیرِ میزبانیشده روی سرور خودتان یکپارچه شوید.
|
|
- بخش قهرمان را بهجای یک گرافیک طراحیشده، با یک عکس واقعی یا عکس محصول بازسازی کنید.
|
|
- بلوک اعتماد را اضافه کنید: آدرس، نقشه، مجوز، تلفن، واتساپ، ساعت کاری و نظرات.
|
|
- فرم تماس را با یک صندوق واقعی بهعلاوهی دکمهی واتساپ جایگزین کنید.
|
|
- هر تصویر را فشرده کنید و صفتهای عرض و ارتفاع را اضافه کنید.
|
|
- لایتهاوس را روی پروفایل موبایل اجرا کنید و برای کارایی، دسترسپذیری و سئو هدف بگذارید: بالای ۹۰.
|
|
- سرچ کنسول را با یک نقشهی سایت تمیز یا یک ابزار آنالیتیکس اختصاصی راهاندازی کنید.
|
|
|
|
## هزینه چقدر است
|
|
|
|
یک قالب آماده از مارکتپلیس چند میلیون تومان است و اصلاحش بیشتر از چیزی که صرفهجویی کردهاید خرج برمیدارد. یک سایت اختصاصی با نکستجیس یا یک سایت ایستا برای کسبوکار کوچک، بسته به تعداد صفحهها، داشتن کاتالوگ و داشتن CMS هدلس، تقریباً ۱۵ تا ۴۵ میلیون تومان است. هاست و نگهداری هم رقم کوچک ماهانهای است. عدد تومان را لنگر بگیرید، چون نرخ ارز تغییر میکند و مقایسه بین واحدهای پولی گمراهکننده است.
|
|
|
|
## حرف آخر
|
|
|
|
سایت یک کسبوکار کوچک نباید طراحها را تحت تأثیر بگذارد. باید روی یک گوشی ارزان در چند ثانیه باز شود، دقیقاً بگوید چه چیزی میفروشد و چطور به آن برسید، و شبیه یک کسبوکار واقعی با آدرس واقعی باشد. بقیهاش تزئین است.
|
|
|
|
## نکات کلیدی
|
|
- چیدمان را موبایلمحور و راستبهچپ طراحی کنید؛ بیشتر ترافیک از بیوی اینستاگرام یا کانال تلگرام میآید.
|
|
- اسلایدر قهرمان، فونتهای اضافه و هر افزونهای که تنها کارش انیمیشن است حذف کنید.
|
|
- عناصر اعتماد همان چیزی است که تبدیل میکند: آدرس واقعی، نقشه، پروانهی کسبوکار، نماد اعتماد، تلفنی که آدمی جواب میدهد و نظر واقعی مشتری.
|
|
- بهجای سبد خرید، کاتالوگ با دکمهی واتساپ بسازید تا خریدار داخل همان اپی کارش را نهایی کند.
|
|
- هدف من LCP زیر ۲.۵ ثانیه و ترجیحاً زیر ۱.۸ ثانیه، اندازهگیریشده روی اینترنت موبایل ایرانی محدود است.
|
|
|
|
## FAQ
|
|
|
|
Q: سایت کسبوکار کوچک من دقیقاً به چه چیزی نیاز دارد؟
|
|
A: باید روی یک گوشی ارزان در چند ثانیه باز شود، دقیقاً بگوید چه چیزی میفروشد و چطور به آن برسید، و شبیه یک کسبوکار واقعی با آدرس واقعی باشد. قرار نیست طراحها را تحت تأثیر بگذارد.
|
|
|
|
Q: سبد خرید بسازم یا فرم رزرو؟
|
|
A: بیشتر این کسبوکارها به کاتالوگ نیاز دارند، نه پلتفرم پرداخت: یک عکس، یک قیمت و دکمهی واتساپ با پیام از پیش نوشتهشده. این بهتر جواب میدهد چون خریدار سفارشش را داخل همان اپی که در آن است نهایی میکند.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'بازار کار ریاکت در ایران؛ استخدام تماموقت یا فریلنسری؟',
|
|
'slug' => 'react-nextjs-job-market-iran-fa',
|
|
'excerpt' => 'توسعهدهندهی ریاکت و نکستجیس ایرانی چطور در سال ۲۰۲۶ بین حقوق ثابت و کار مستقل انتخاب کند؛ بههمراه اینکه بازار واقعاً چقدر پرداخت میکند.',
|
|
'category' => 'career-fa',
|
|
'tags' => ['react-fa', 'nextjs-fa', 'career-fa'],
|
|
'cover' => 'بازار کار ریاکت در ایران',
|
|
'views' => 2100,
|
|
'likes' => 150,
|
|
'days_ago' => 3,
|
|
'body' => <<<'TEXT'
|
|
# بازار کار ریاکت در ایران؛ استخدام تماموقت یا فریلنسری؟
|
|
|
|
تقریباً هر هفته کسی از من میپرسد که آیا برای شغل ریاکت در ایران همچنان اپلی کند یا مستقل کار کند. پاسخ صادقانه این است که هر دو مسیر وجود دارند، اما پرداختشان تفاوت فاحشی دارد و انتخاب درست بیشتر به سطح شما و ذخیرهی مالیتان بستگی دارد تا به فریمورک. بازار را آنطور که در سال ۲۰۲۶ میبینم این است.
|
|
|
|
## تقاضای واقعی چه شکلی است
|
|
|
|
ریاکت هنوز برای هر چیزی که شبیه محصول است در ایران انتخاب پیشفرض است: داشبورد، پنل ادمین، محصولات SaaS و سایتهای بزرگ فروشگاهی و محتوایی. نکستجیس هم برای هر چیزی که رو به عموم است تقریباً اجباری شده. اما بازار از چند سال پیش کوچکتر است. سرمایهگذاری کم است، تیمها کوچکاند و بخش بزرگی از کاری که «استارتاپی» نامیده میشود، در واقع نگهداری محصولات قدیمیتر است. نتیجه اینکه سطح انتظار بالا رفته. یک توسعهدهندهی جیونیور ریاکت بدون پایهی قوی دارد سختی میکشد. یک مهندس ارشدی که میتواند یک فیچر را از طراحی تا تولید مالکیت کند، سختی نمیکشد.
|
|
|
|
## استکهایی که شما را استخدام میکنند
|
|
|
|
- تایپاسکریپت همهجا، حالت strict، و بدون هیچ `any` در یک پولریکوئست.
|
|
- اپروتر نکستجیس با کامپوننتهای سرور ریاکت، سرور اکشنها و استریمینگ، بهعلاوهی قضاوت واقعی دربارهی اینکه مرز کلاینت کجا باید باشد.
|
|
- تسلط بر لایهی داده: پریزما یا درایزل، کوئریهایی که آببازی نیستند، و دانستن اینکه چه وقت خود کوئری مشکل اصلی است.
|
|
- تستی که تزئینی نیست: ویتست یا جست با ریاکت تستینگلبرری، و پلیرایت برای مسیرهای حیاتی.
|
|
- کارایی و قابلیت مشاهده: شاخصهای Core Web Vitals، استراتژی کش، بودجهی باندل و ردیابی خطا.
|
|
- بکاند بهقدری که هیچوقت جلویتان را نگیرد: نود، صف، کرون، احراز هویت، ذخیرهسازی اشیا و استقراری که ساعت دو بامداد بتوانید دیباگش کنید.
|
|
- داکر، پایپلاینهای CI و زیرساخت بهعنوان کد، دستکم در حدی که گلوگاه نباشید.
|
|
|
|
کار پروژهای معمولاً کل این فهرست را میخواهد. به همین دلیل است که اینجا خیلیها خودشان را فولاستک معرفی میکنند، حتی وقتی بکاندشان یک فایل بیشتر نیست.
|
|
|
|
## واقعیت حقوق و دستمزد
|
|
|
|
برای موقعیتهای حضوری در تهران، یک مهندس قویِ مید تا سنیور ریاکت یا نکستجیس معمولاً ماهانه بین ۶۰ تا ۱۲۰ میلیون تومان میگیرد که سقف این بازه در شرکتهای محصول و شرکتهای مشاورهای با مشتری خارجی متمرکز است. نقشهای استاف و لید بیشتر میگیرند، ولی تعدادشان بسیار کم است. جیونیور و مید خیلی پایینتر جمع میشوند و فاصلهی پلهها پهن است.
|
|
|
|
بعد نوبت دورکاری برای پیمانکار ایرانی است و اینجاست که فاصلهی واقعی دیده میشود. دورکاری برای یک شرکت ایرانی معمولاً کمتر از معادل حضوری پرداخت میکند، چون اجارهی دفتر را از شرکت حذف میکنید و طرف مقابل هم این را میداند. دورکاری برای کارفرمای خارجی چند برابر و به پول سخت پرداخت میکند، اما موانع عینی است: تحریمها، سختی باز کردن حساب و دریافت پول، همپوشانی با ساعات اروپا و مصاحبه به انگلیسی. غیرممکن نیست و تعدادی از مهندسانی که میشناسم مدیریتش میکنند، ولی برنامهی پیشفرض نیست.
|
|
|
|
## استخدام یا فریلنسری
|
|
|
|
- زیر دو سال تجربهی واقعی: استخدام را انتخاب کنید. به بازبینی کد، راهنمایی و کسی نیاز دارید که مسئول خرابیها باشد.
|
|
- دو تا پنج سال تجربه همراه با شبکهی ارتباطی: ترکیبی بهترین جواب است. حقوق برای ثبات، شبها یا آخر هفتهها برای کارهای نگهداری ماهانه.
|
|
- ارشد، با اعتبار و حدود شش ماه ذخیرهی مالی: فریلنسری میتواند از حقوق جلو بزند، اما فقط با قرارداد مکتوب، پیشپرداخت و کنترل سختگیرانهی دامنهی کار.
|
|
- اگر اجاره یا خرج خانه از این درآمد را میدهید: حقوق ثابت را نگه دارید. درآمد فریلنسری نوسانی است و ماه ساکت عادی است، نه شکست.
|
|
|
|
## موتوری که واقعاً پیشنهاد میسازد
|
|
|
|
- دو یا سه مطالعهی موردی عمیق، هر کدام با مسئله، محدودیتها، تصمیمهای شما و یک عدد. عدد بیشتر از اسکرینشات مینشیند.
|
|
- انگلیسی، اول نوشتاری. بیشتر گفتوگوهای دورکاری بخشی از استخدام را بر پایهی این میگذارند که چقدر واضح مینویسید و توضیح میدهید.
|
|
- یک مشارکت واقعی در متنباز. نه یک کلون آموزشی، بلکه یک پولریکوئست یا یک کتابخانهی کوچک با کاربر واقعی.
|
|
- لینکدین تمیز و سایت پورتفویویی که سریع باز میشود. پورتفویوی کند در این حوزه سیگنال بدی است.
|
|
|
|
## مذاکره
|
|
|
|
عدد حقوق فعلیتان را اول نگویید. بازهی تأییدشده را بپرسید. به خاطر داشته باشید کارمند ایرانی از طریق فیش حقوق به تأمین اجتماعی کمک میکند که در مقایسه با صدور فاکتور فریلنسری، بخش قابلتوجهی از بستهی شما را تشکیل میدهد و آنجا کل مبلغ را خودتان میدهید. دربارهی پاداش، ساعات کاری، مرخصی و اینکه ابزار یا آموزش را پرداخت میکنند یا نه بپرسید. با کارفرمای خارجی، واحد پول، نرخ و شرایط پرداخت را پیش از شروع کار مکتوب کنید و همیشه پیشپرداخت بگیرید.
|
|
|
|
وقتی هنوز به یادگیری سریع نیاز دارید استخدام را انتخاب کنید. وقتی مهارت و شبکهی ارتباطی را دارید فریلنسری را. بازار این را برای شما تصمیم نمیگیرد.
|
|
|
|
## نکات کلیدی
|
|
- ریاکت هنوز برای هر چیزی که شبیه محصول است انتخاب پیشفرض است، اما سطح انتظار برای جیونیور بدون پایهی قوی بالا رفته.
|
|
- کل عرض استک را یاد بگیرید: لایهی داده، تست واقعی، کارایی و قابلیت مشاهده، بهعلاوهی بکاندی که ساعت دو بامداد بتوانید دیباگش کنید.
|
|
- مدل درآمدی را با مرحلهی شغلی هماهنگ کنید: استخدام در ابتدا، ترکیبی در میانه، فریلنسری فقط با حدود شش ماه ذخیرهی مالی.
|
|
- دو یا سه مطالعهی موردی عمیق بسازید که هر کدام به یک عدد ختم شود؛ عدد بیشتر از اسکرینشات مینشیند.
|
|
- عدد حقوق فعلیتان را اول نگویید؛ بازهی تأییدشده و سهم تأمین اجتماعی را در بسته حساب کنید.
|
|
|
|
## FAQ
|
|
|
|
Q: استخدام بهتر است یا فریلنسری؟
|
|
A: انتخاب بیشتر به سطح و ذخیرهی مالی شما بستگی دارد تا به فریمورک. زیر دو سال تجربهی واقعی، استخدام را انتخاب کنید چون به بازبینی کد و راهنمایی نیاز دارید. ارشد با حدود شش ماه ذخیرهی مالی، فقط با قرارداد مکتوب و پیشپرداخت میتواند از حقوق جلو بزند.
|
|
|
|
Q: دورکاری برای کارفرمای خارجی شدنی است؟
|
|
A: بله، چند برابر به پول سخت پرداخت میکند و چند مهندس آن را مدیریت میکنند، اما برنامهی پیشفرض نیست. موانع عینی است: تحریمها، سختی دریافت پول، همپوشانی با ساعات اروپا و مصاحبه به انگلیسی.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'مهاجرت از وردپرس به نکستجیاس برای وبسایتهای فارسی',
|
|
'slug' => 'wordpress-to-nextjs-migration-fa',
|
|
'excerpt' => 'مسیر مرحلهبهمرحله از یک سایت کند وردپرسی به یک سایت سریع نکستجیس، با حفظ محتوای فارسی، آدرسهای فارسی و ترافیک جستوجو.',
|
|
'category' => 'react-nextjs-fa',
|
|
'tags' => ['react-fa', 'nextjs-fa', 'performance-fa'],
|
|
'cover' => 'مسیر مهاجرت به نکستجیاس',
|
|
'views' => 2300,
|
|
'likes' => 170,
|
|
'days_ago' => 1,
|
|
'body' => <<<'TEXT'
|
|
# مهاجرت از وردپرس به نکستجیاس برای وبسایتهای فارسی
|
|
|
|
وردپرس هنوز بخش بزرگی از وب فارسی را اداره میکند، از سایت شرکتهای کوچک تا ناشران بزرگ. دلیلش دلایل خوبی داشته، اما بسیاری از این سایتها امروز به خاطر قالب و صفحهساز، نه محتوا، در Core Web Vitals امتیاز بدی میگیرند. این همان مسیر مرحلهای است که برای مهاجرت بدون از دست دادن ترافیک جستوجو به کار میبرم.
|
|
|
|
## چرا این سؤال اینقدر زیاد مطرح میشود
|
|
|
|
- وردپرس در وب فارسی مسلط است، پس بیشتر کسبوکارها سالها آدرس، بکلینک و محتوایی دارند که از دست دادنشان را نمیخواهند.
|
|
- صفحهسازهایی مثل WPBakery، المنتور و دیوی بستههای بزرگ CSS و جاوااسکریپت، جیکوئری و درخت DOM عظیم تحویل میدهند. اینها LCP و INP را میکشند، نه تصاویر و نه هاست.
|
|
- افزونههای فارسی برای فرم، اسلایدر، سئو و ترجمه هر کدام وزن اضافه میکنند و ریسک نگهداری و امنیت هستند.
|
|
- مالک میخواهد محتوا را بدون دست زدن به کد ویرایش کند و این نیاز در مهاجرت از بین نمیرود.
|
|
|
|
## مرحلهی یک: ممیزی و خط پایه
|
|
|
|
قبل از هر تغییری عددها را ثبت کنید تا جواب مهاجرت را ثابت کنید. سایت را کراول کنید و هر آدرس ایندکسشده را با کد وضعیت و کانونیکال استخراج کنید. دوازده ماه دادهی سرچ کنسول را بیرون بکشید و صفحات فرود برتر را مشخص کنید. لایتهاوس را با پروفایل موبایل روی چند قالب نماینده اجرا و LCP، INP و CLS را ذخیره کنید. تنظیمات آنالیتیکس را هم بررسی کنید؛ همین یک چیز در هر مهاجرتی بیسروصدا خراب میشود.
|
|
|
|
## مرحلهی دو: بیرون کشیدن محتوا
|
|
|
|
REST API برای محتوای استاندارد مسیر تمیزی است: هر نوع محتوا یک آندپوینت دارد و نتایج صفحهبندی میشوند، پس اسکریپتی بنویسید و تا گرفتن همهچیز صفحهها را دنبال کنید. حواستان به نوعهای محتوای سفارشی و فیلدهای سفارشی باشد، چون آندپوینت پیشفرض آنها را برنمیگرداند و باید اول ثبتشان کنید. خروجی WP-CLI به JSON همهی پایگاه داده را در یک فایل میدهد. رسانهها را جداگانه خروجی بگیرید و نام فایلهای اصلی را نگه دارید.
|
|
|
|
## مرحلهی سه: انتخاب معماری محتوا
|
|
|
|
دو گزینهی واقعی دارید. یا وردپرس را CMS هدلس نگه میدارید و محتوا را در زمان بیلد یا درخواست میگیرید؛ کارفرما ویرایشگر آشنایش را نگه میدارد و شما فرانتاند نکستجیس را میگیرید، در ازای پذیرش یک هدف متحرک. یا همهچیز را به مارکداون، MDX یا CMS هدلس وارد میکنید و صفحههای ایستا میسازید؛ وقتی محتوا فقط چند بار در هفته عوض شود، این روش سریعتر و باثباتتر است. بیشتر کارفرمایان من در نهایت محتوای ایستا بهعلاوهی یک ابزار ویرایش کوچک را انتخاب میکنند.
|
|
|
|
## مرحلهی چهار: آدرسها، اسلاگها و ریدایرکتها
|
|
|
|
مهاجرتها اینجا برنده یا بازنده میشوند. هر آدرس قدیمی را به آدرسی جدید نگاشت کنید و ساختار مسیر را یکسان نگه دارید. آدرسی را که نمیتوانید حفظ کنید، با ۳۰۱ به نزدیکترین معادل بفرستید، نه صفحهی اول. اسلاگهای فارسی و عربی را همانطور که بود، دستنخورده و نرمالنشده، نگه دارید؛ تغییرشان لینکها را میشکند و سایت را برای موتور جستوجو نو نشان میدهد. صفحهبندی، آرشیو تاریخی، صفحههای برچسب، فیدها و صفحههای پیوست را هم نگاشت کنید؛ معمولاً فراموش و ایندکس میشوند. نقشهی سایت جدید را بسازید و نقشهی قدیمی را پشت ریدایرکتها نگه دارید.
|
|
|
|
## مرحلهی پنج: ساخت سریع
|
|
|
|
بهصورت پیشفرض از تولید ایستا استفاده کنید و بازتولید افزایشی را فقط جایی بگذارید که محتوا بیشتر از روزی یک بار تغییر میکند؛ مثل صفحهی اخبار. تصاویر را با کامپوننت تصویر فریمورک و فرمت مدرن سرو کنید. زبان و جهت را روی عنصر سند با `lang="fa"` و `dir="rtl"` بگذارید و CSS را با ویژگیهای منطقی مثل `margin-inline-start` بنویسید تا در هر دو جهت درست کار کند.
|
|
|
|
## تایپوگرافی فارسی، درست و حسابی
|
|
|
|
سراغ بارگذار فونت گوگل نروید. گوگل فونتس روی بیشتر شبکههای ایران فیلتر است، پس فونتی که از دامنهی گوگل گرفته شود یا شکست میخورد یا به فونت سیستم برمیگردد. یک فونت متغیر فارسی مثل وزیرمتن را روی سرور خودتان میزبانی و با `next/font/local` ثبتش کنید تا پریلود را نکستجیس مدیریت کند. یک فایل، دو یا سه وزن، `font-display: swap` و ارتفاع خط درست. ارقام فارسی و تاریخ شمسی را پیش از لانچ چک کنید.
|
|
|
|
## گلاچها
|
|
|
|
- آدرس رسانهها. فایلهای آپلود را به هاست جدید کپی کنید، نام فایلها را یکسان نگه دارید و ارجاعهای ثابت درون نوشتههای قدیمی را درست کنید. آدرس تصویر کهنه از دلایل رایج محتوای مختلط است.
|
|
- فرم کامنت. کامنتهای مبتنی بر افزونه بهندرت جان سالم به در میبرند. زود تصمیم بگیرید نگهشان میدارید یا نه؛ اگر نگه میدارید یک فرم ساده با نظارت بسازید.
|
|
- آنالیتیکس. سرویسهای گوگل از داخل ایران قابل اتکا نیستند. مطمئن شوید ارائهدهندهی شما برای بازدیدکنندگانتان لود میشود، یا یک ابزار اختصاصی بدون کوکی را میزبانی کنید تا سابقه از دست نرود.
|
|
- جستوجو. آندپوینت جستوجوی وردپرس دیگر وجود نخواهد داشت. اگر سایت به آن تکیه کرده بود، ایندکس واقعی اضافه کنید یا جستوجوی داخلی را بپذیرید.
|
|
- محتوای مختلط، آدرسهای `http` خام درون محتوای قدیمی و استایلها و اسکریپتهای درونخطی که کسی ممیزی نکرده است.
|
|
- تست: هر ریدایرکت با curl، هر کد وضعیت، و بعد لایتهاوس نهایی روی همان قالبهای مرحلهی اول.
|
|
|
|
## موفقیت چه شکلی است
|
|
|
|
قبل و بعد را روی صفحههای یکسان مقایسه کنید. روی سایتهایی که مهاجرت دادهام، LCP معمولاً از چهار یا پنج ثانیه به زیر دو ثانیه میافتد و INP حتی بیشتر بهتر میشود چون صفحهساز حذف شده است. ترافیک باید بعد از جاافتادن ریدایرکتها ثابت بماند و بهخاطر سرعت رشد کند. قالبها را یکییکی مهاجرت دهید و اعتبار جستوجو را معامله نکنید.
|
|
|
|
## نکات کلیدی
|
|
- قبل از هر تغییری خط پایه را ثبت کنید: همهی آدرسهای ایندکسشده با کد وضعیت، دوازده ماه دادهی سرچ کنسول و مقادیر LCP، INP و CLS هر قالب.
|
|
- صفحهسازها هستند که LCP و INP را میکشند، نه تصاویر و نه هاست؛ حذف همانها بیشترین اثر را دارد.
|
|
- هر آدرس قدیمی را به معادل جدید نگاشت کنید و ساختار مسیر را یکسان نگه دارید؛ ۳۰۱ به نزدیکترین معادل، نه به صفحهی اول.
|
|
- اسلاگهای فارسی و عربی را دستنخورده و نرمالنشده نگه دارید؛ نرمالسازی لینکها را میشکند و اعتبار جستوجو را از بین میبرد.
|
|
- بهصورت پیشفرض تولید ایستا کنید و بازتولید افزایشی را فقط جایی بگذارید که محتوا روزانه عوض میشود.
|
|
|
|
## FAQ
|
|
|
|
Q: چرا LCP سایت وردپرسی من پایین است؟
|
|
A: در بیشتر موارد قالب و صفحهساز مقصرند، نه تصویر و نه هاست؛ صفحهسازها بستههای بزرگ CSS و جاوااسکریپت، جیکوئری و درخت DOM عظیم تحویل میدهند. LCP معمولاً از چهار یا پنج ثانیه به زیر دو ثانیه میافتد.
|
|
|
|
Q: وردپرس را CMS نگه دارم یا نه؟
|
|
A: یا وردپرس را CMS هدلس نگه دارید و محتوا را در زمان بیلد بگیرید، یا همهچیز را به مارکداون، MDX یا CMS هدلس وارد کنید و صفحههای ایستا بسازید. بیشتر کارفرمایان من محتوای ایستا با یک ابزار ویرایش کوچک را انتخاب میکنند.
|
|
TEXT,
|
|
],
|
|
[
|
|
'title' => 'معماری تمیز در لاراول',
|
|
'slug' => 'clean-architecture-laravel-fa',
|
|
'excerpt' => 'یک تقسیمبندی کاربردی برای لاراول که Eloquent را در مرز نگه میدارد، جهت وابستگیها را رعایت میکند و از اضافهکاری در پروژههای کوچک جلوگیری میشود.',
|
|
'category' => 'backend-fa',
|
|
'tags' => ['laravel-fa', 'clean-code-fa'],
|
|
'cover' => 'معماری تمیز در لاراول',
|
|
'views' => 1940,
|
|
'likes' => 136,
|
|
'days_ago' => 8,
|
|
'body' => <<<'TEXT'
|
|
# معماری تمیز در لاراول
|
|
|
|
معماری تمیز معمولاً با انبوهی از اصطلاحات مثل Entity، UseCase، Port و Adapter آموزش داده میشود. این مفاهیم در تئوری مفیدند، ولی در پروژههای واقعی لاراول اغلب باعث اضافهکاری میشوند. هدف اصلی این نیست که همه قوانین را رعایت کنیم، بلکه این است که منطق کسبوکار را مستقل از فریمورک نگه داریم تا کد پایه سالها دوام بیاورد.
|
|
|
|
## تقسیمبندی کاربردی
|
|
|
|
یک راه ساده و آزمودهشده، تقسیم کد به سه لایه اصلی است: Domain، Application و Infrastructure. این تقسیمبندی جهت وابستگیها را واضح نگه میدارد بدون اینکه نیاز به بیست Namespace مختلف داشته باشیم.
|
|
|
|
لایه Domain شامل مفاهیم اصلی کسبوکار است. Entityها، Value Objectها، Enumها و قوانین دامنه در این لایه قرار میگیرند. هیچچیز در Domain نباید به لاراول، Eloquent، HTTP یا APIهای خارجی وابسته باشد. این لایه باید فقط PHP خالص باشد.
|
|
|
|
لایه Application شامل UseCaseهاست؛ یعنی کاری که سیستم انجام میدهد. در این لایه جریانهای کاری هماهنگ میشوند، قوانین کسبوکار اعمال میشوند و Interfaceهایی برای وابستگیهای خارجی تعریف میگردند. Application فقط به Domain وابسته است و هیچ اطلاعی از Controllerها، Jobها یا دیتابیس ندارد.
|
|
|
|
لایه Infrastructure لایه بیرونی است. جایی که لاراول زندگی میکند: مدلهای Eloquent، Repositoryها، Jobها، کلاینتهای HTTP، سرویسهای تماس با شخص ثالث و کدهای مخصوص فریمورک. Infrastructure Interfaceهای تعریفشده در Application را پیادهسازی میکند و هم به Application و هم به Domain وابسته است.
|
|
|
|
## نگه داشتن Eloquent در مرز Repository
|
|
|
|
یکی از رایجترین اشتباهات این است که Eloquent را همهجا پخش میکنیم. Eloquent بسیار راحت است، ولی منطق کسبوکار را به اسکیمای دیتابیس و قابلیتهای فریمورک گره میزند. راهکار کاربردی این است که Eloquent را یک جزئیات پیادهسازی در نظر بگیریم.
|
|
|
|
Interfaceهای Repository را در لایه Application تعریف کنید. مثلاً یک Interface به نام OrderRepository با متدهایی مثل findById یا save. سپس این Interface را در Infrastructure با استفاده از مدلهای Eloquent پیادهسازی کنید. UseCaseها فقط به Interface وابستهاند، نه به خود مدلها. این کار تستپذیری را بالا میبرد و تعویض پیادهسازی را آسان میکند.
|
|
|
|
همچنین از برگرداندن Collection یا Modelهای Eloquent از Repository به لایه Application خودداری کنید. آنها را به Entityهای Domain یا DTOهای ساده نگاشت کنید. این کار مرز را تمیز نگه میدارد و از نفوذ Lazy Loading یا رفتارهای فریمورک به داخل منطق کسبوکار جلوگیری میکند.
|
|
|
|
## جهت وابستگیها اهمیت دارد
|
|
|
|
قانون اصلی این است: وابستگیها باید به سمت داخل باشند. Infrastructure میتواند به Application و Domain وابسته باشد. Application فقط به Domain وابسته است. Domain به هیچ چیز بیرونی وابسته نیست. این همان اصل کلیدی برای جدا کردن کد از فریمورک است.
|
|
|
|
Controllerها، Routeها، Jobها و Commandها در Infrastructure قرار میگیرند. باید نقش هماهنگکننده نازکی داشته باشند. آنها UseCaseهای Application را صدا میزنند، درخواست HTTP را به DTO تبدیل میکنند و پاسخ را برمیگردانند. اگر Controller شما اعتبارسنجی، محاسبات پیچیده یا Queryهای سنگین انجام میدهد، احتمالاً آن منطق باید به Application یا Domain منتقل شود.
|
|
|
|
## کی نباید لایهبندی را زیادهروی کنیم
|
|
|
|
معماری تمیز هزینه دارد. برای یک پروژه CRUD کوچک، اضافه کردن سه لایه برای هر قابلیت، باعث پیچیدگی بیخودی میشود. اگر برنامهتان بیشتر ورود داده است و منطق کسبوکار کمی دارد، ساختار سنتی لاراول کاملاً کافی است.
|
|
|
|
زمانی که باید لایهبندی اضافه کنیم، وقتی پیچیدگی افزایش مییابد. اگر قوانین کسبوکار غیرپیشپاافتاده دارید، چندین سرویس خارجی را یکپارچه میکنید یا احتمال دارد دامنه کسبوکار از انتخاب فریمورک زندهتر بماند، این سرمایهگذاری ارزش دارد. اگر هنوز در مرحله اعتبارسنجی ایده هستید، ساده بمانید و هرزمان پیچیدگی پدید آمد، بهتدریج به این مرزها نزدیک شوید.
|
|
|
|
## ساختار پوشهها به شکل کاربردی
|
|
|
|
یک ساختار حداقلی و قابلنگهداری این است: در پوشه app، سه پوشه Domain، Application و Infrastructure ایجاد کنید. یا اگر ترجیح میدهید از src استفاده کنید. پوشههای پیشفرض لاراول را هرجا منطقی است نگه دارید، ولی منطق کسبوکار را خارج کنید.
|
|
|
|
Domain میتواند شامل Entities، ValueObjects، Enums و Exceptionهای مخصوص دامنه باشد. Application شامل UseCases، Contracts (Interfaceها)، DTOs و Policies باشد. Infrastructure شامل Repositories، Services، Jobs، Http/Controllers و Adapterهای مخصوص فریمورک باشد.
|
|
|
|
این ساختار باعث میشود Namespaceها شفاف باشند و هر توسعهدهنده جدید بداند کد جدید را کجا قرار دهد. با رعایت جهت وابستگیها، بدون نیاز به حفظ کردن تمام اصطلاحات پیچیده میتوان کد تمیزی داشت.
|
|
|
|
## نکات کلیدی
|
|
|
|
- کد را به Domain، Application و Infrastructure تقسیم کنید تا منطق کسبوکار مستقل از فریمورک بماند.
|
|
- Interfaceهای Repository را در Application تعریف کنید و پیادهسازی آنها را با Eloquent در Infrastructure انجام دهید.
|
|
- مدلهای Eloquent را در مرز به Entityهای Domain یا DTO نگاشت کنید و هیچگاه آنها را به داخل نفوذ ندهید.
|
|
- قانون وابستگی رو به داخل را رعایت کنید: Infrastructure به بیرون وابسته است و Domain به هیچ چیز وابسته نیست.
|
|
- فقط زمانی لایهبندی کنید که پیچیدگی کسبوکار آن را توجیه کند. پروژههای CRUD کوچک به معماری تمیز کامل نیاز ندارند.
|
|
|
|
## FAQ
|
|
|
|
Q: آیا باید Eloquent را کنار بگذارم؟
|
|
A: نه. Eloquent ORM بسیار خوبی است. آن را در Infrastructure نگه دارید و پشت Interfaceهای Repository پنهان کنید.
|
|
|
|
Q: این ساختار با معماری هگزاگونال یکی است؟
|
|
A: ایده مشابهی دارد با نام متفاوت. هدف، جدا کردن هسته از وابستگیهای خارجی با الگوی Port و Adapter است. این تقسیمبندی کاربردی همان هدف را بدون انبوه اصطلاحات دنبال میکند.
|
|
|
|
Q: چطور این ساختار را تست کنم؟
|
|
A: لایه Domain و Application را با تستهای واحد سریع تست کنید (بدون لاراول). لایه Infrastructure را با تستهای یکپارچگی و در صورت نیاز با دیتابیس یا Mock تست کنید. این کار حلقه بازخورد را سریع نگه میدارد.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'یک گردش کار گیت و بازبینی کد که فراتر از پنج توسعهدهنده جواب میدهد',
|
|
'slug' => 'git-branching-and-reviews-fa',
|
|
'excerpt' => 'گلوگاه، استراتژی شاخهبندی نیست، کیفیت بازبینی کد است. شاخههای کوتاهعمر، کامیتهای اتمیک، محافظت از main و چکهای خودکار، یک تیم پنجنفره را به بیستنفره میرساند بدون آنکه بحثی بماند.',
|
|
'category' => 'engineering-practices-fa',
|
|
'tags' => ['git-fa', 'clean-code-fa'],
|
|
'cover' => 'گردش کار گیت و بازبینی کد',
|
|
'views' => 2340,
|
|
'likes' => 155,
|
|
'days_ago' => 17,
|
|
'body' => <<<'TEXT'
|
|
# یک گردش کار گیت و بازبینی کد که فراتر از پنج توسعهدهنده جواب میدهد
|
|
|
|
بیشتر تیمها وقتی حوالی شش توسعهدهنده به بنبست میرسند، استراتژی شاخهبندی را مقصر میگیرند. چیزی که واقعاً با زیادشدن تعداد نفرات خراب میشود، کیفیت و سرعت بازبینی کد است. این همان گردش کاری است که روی هر پروژه نصب میکنم، بههمراه دلیل هر تکه از آن.
|
|
|
|
## شاخههای کوتاهعمر بر شاخههای بلندعمر میبرند
|
|
|
|
شاخهای که سه هفته زندگی میکند، سه هفته تغییرات دیگران را با خود دارد که ندیدهاید و در پایانش به یک merge دردناک ختم میشود. شاخه وجود دارد تا موازی کار کنید و بعد چیزی قابل بازبینی به نفر بعدی بدهید.
|
|
|
|
- شاخه را همان روزی که شروع میکنید باز کنید و ظرف یک روز merge کنید.
|
|
- اگر زود merge نمیشود، یعنی تغییر بزرگ است. آن را بشکنید.
|
|
- شاخههای آزمایشی بلندعمر فقط وقتی جواب میدهند که آن کد در این فاصله منتشر نشود.
|
|
- شاخهها را بعد از merge پاک کنید، وگرنه هیچکس نمیفهمد کدام کار واقعی است.
|
|
|
|
## trunk based در برابر feature branch، در عمل
|
|
|
|
این دو مقابل هم نیستند. trunk based یعنی main همیشه قابل انتشار است، و شاخه کوتاهمدت در دل آن کاملاً اشکالی ندارد. از main برای چند ساعت کار شاخه میزنید، pull request باز میکنید و بعد از بازبینی merge میکنید. قطب مقابل را کنار بگذارید، جایی که هر توسعهدهنده یک شاخه شخصی چندماهه نگه میدارد. آن مدل تا اولین باری که دو نفر یک مایگریشن را لمس میکنند کار میکند.
|
|
|
|
## کامیتهایی که اتمیک و قابل بازبینیاند
|
|
|
|
کامیت واحد معناست نه واحد زمان. یک کار میکند، بهتنهایی تستها را پاس میکند و بهتنهایی برمیگردد. همین ویژگی است که به شما bisect و revert تمیز میدهد.
|
|
|
|
- بازآرایی کد را از تغییر رفتار جدا کنید.
|
|
- پیام کامیت را برای کسی بنویسید که شش ماه بعد bisect میکند.
|
|
- اینکه چرا تغییر رخ داد مهمتر از چیزی است که diff از قبل نشان میدهد.
|
|
- تاریخچه را کوتاه نگه دارید. ده کامیت از کار یک روزه اشکالی ندارد.
|
|
|
|
## بازبینی خوب واقعاً چه چیزی را بررسی میکند
|
|
|
|
بازبینی برای درستی و برای فهم مشترک است، نه برای قالببندی. یک formatter در CI از قبل مالک indentation، ترتیب import و طول خط است. بازبینندهای که حوصلهاش را صرف همانها میکند، مشکلات واقعی را دستنخورده رها میکند.
|
|
|
|
- آیا همان کاری را میکند که تیکت گفته، شامل بخشهای نانوشته، و نه بیشتر؟
|
|
- با ورودی خالی، ورودی خیلی بزرگ و درخواستهای همزمان چه میشود؟
|
|
- تستها رفتار را پوشش میدهند یا فقط پیادهسازی را تکرار میکنند؟
|
|
- آیا چیز حساسی در diff هست، مثل توکن، شناسه شخصی یا کوئری بدون محدودیت؟
|
|
- آیا یک تازهوارد این را شش ماه بعد میفهمد؟
|
|
|
|
کامنتها باید بگویند چه چیزی و چرا، نه فقط چه چیزی. بازبینی پر از خطهای تکرارشده، نویز است و بازبینی نویزی سرسری خوانده میشود.
|
|
|
|
## محافظت از main و خودکارسازی چکهای خستهکننده
|
|
|
|
ارزانترین راه سریعکردن بازبینی، حذف سؤالهایی است که بازبیننده هرگز نباید مجبور به پرسیدنشان باشد. هر چیز مکانیکی جای CI است، چون یک آدم نباید یک دور بازبینی را صرف نبودن یک newline کند.
|
|
|
|
- برای main پولریکاینت با حداقل یک تأیید اجباری کنید.
|
|
- push مستقیم به main را ببندید.
|
|
- format، lint، typecheck و تست را status check اجباری کنید.
|
|
- پایپلاین را زیر ده دقیقه نگه دارید و با رشد آن موازیسازی کنید.
|
|
- با squash یا rebase merge کنید تا main خطی بماند.
|
|
|
|
## جمعبندی
|
|
|
|
- برای ساعتها شاخه بسازید نه هفتهها، چون هزینه بازبینی با اندازه diff رشد میکند.
|
|
- main را همیشه قابل انتشار نگه دارید و شاخههای کوچک را روزانه داخل آن merge کنید.
|
|
- کامیتهای اتمیک با پیامی بنویسید که برای bisect آینده مفید باشد.
|
|
- رفتار و ریسک را بازبینی کنید و قالببندی را به formatter بسپارید.
|
|
- هر چک مکانیکی را خودکار کنید تا توجه بازبیننده صرف درستی شود.
|
|
|
|
## FAQ
|
|
|
|
Q: توسعه trunk based برای تیمی که ماهی یکبار منتشر میکند کار میکند؟
|
|
|
|
A: بله، و برای انتشار ماهانه بهتر از شاخههای بلندعمر است. شما هر روز داخل main کد را merge میکنید و با تگ یا feature flag کنترل میکنید چه چیزی زنده برود، پس main قابل انتشار میماند و خودِ انتشار طبق برنامه شما انجام میشود.
|
|
|
|
Q: بازبینیهای ما کند است، آیا باید دو تأیید اجباری کنیم؟
|
|
|
|
A: اولویت اول نیست. بازبینی کند معمولاً یعنی diff خیلی بزرگ است، تیکت مبهم است یا نویسنده دیر درخواست داده. اول هر سه را درست کنید و مطمئن شوید چکهای مکانیکی در CI اجرا میشوند تا بازبیننده نقش لینتر را بازی نکند. بعد از آن سختگیرتر کردن مایگریشن و کد احراز هویت منطقی است.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'ایندکسهای SQL که کوئری را سریع میکنند: راهنمای عملی با لاراول',
|
|
'slug' => 'sql-indexes-database-performance-fa',
|
|
'excerpt' => 'کندی یک اندپوینت لاراول تقریباً هیچوقت از سرور نیست، از نبود ایندکس روی ستون کوئری است. اینجا یاد میگیرید EXPLAIN را چطور بخوانید، ترتیب ستونهای ایندکس مرکب را چطور بچینید و با ایندکس روی کلید خارجی نوشتن را کند نکنید.',
|
|
'category' => 'backend-fa',
|
|
'tags' => ['database-fa', 'performance-fa'],
|
|
'cover' => 'ایندکس و کوئریهای سریع',
|
|
'views' => 1960,
|
|
'likes' => 128,
|
|
'days_ago' => 9,
|
|
'body' => <<<'TEXT'
|
|
# ایندکسهای SQL که کوئری را سریع میکنند: راهنمای عملی با لاراول
|
|
|
|
تقریباً هر اندپوینت کندی که برایش بررسی میکنم یک علت مشترک دارد: اسکن کامل جدولی روی ستونی که هیچ ایندکسی ندارد. لاراول نوشتن این کوئری را آسان میکند و فراموشکردنش را هم آسان، چون کسی متوجه نمیشود تا جدول از صد هزار ردیف عبور نکند.
|
|
|
|
## ایندکس واقعاً چه کار میکند
|
|
|
|
MySQL و PostgreSQL ایندکسها را در یک درخت B ذخیره میکنند، درختی که کلیدهایش مرتب میماند و برگهایش کنار هم در حافظه مینشینند. همین یک ویژگی رفتار را توضیح میدهد: پیدا کردن یک کلید فقط چند صفحه را لمس میکند نه همه ردیفها را، و دو شرط روی یک ستون با یک بار پیمایش درخت از ابتدای بازه تا انتهای آن سرو میشود.
|
|
|
|
نیمه دیگر ماجرا هم مهم است: هر insert و هر update باید در هر ایندکس جدول هم نوشته شود، پس ایندکس مالیاتی است که روی نوشتن میپردازید تا خواندن سریع شود.
|
|
|
|
## خواندن EXPLAIN بدون حدس زدن
|
|
|
|
EXPLAIN را روی کوئری واقعی با پارامترهای واقعی اجرا کنید و از بالا به پایین بخوانید: نوع دسترسی، تعداد ردیف تخمینی، درصد فیلتر و ستون extra.
|
|
|
|
- اسکن ترتیبی روی جدول بزرگ یعنی ایندکس قابل استفادهای نیست. ستون و نوع مقدار را بررسی کنید.
|
|
- اسکن با ایندکس و تعداد ردیف تخمینی بسیار زیاد یعنی ایندکس برای بهینهساز بهاندازه کافی گزینشی نیست.
|
|
- عبارت rows removed by a filter معمولاً یعنی وایلدکارت یا عبارتی که قابل استفاده از ایندکس نیست.
|
|
- temporary table یا filesort یعنی ORDER BY از ترتیب ایندکس سرو نشد، پس اول ایندکس را درست کنید.
|
|
- زیرکوئری وابسته معمولاً به الگوی N بهعلاوه یک در Eloquent اشاره دارد، یک کوئری بهازای هر ردیف والد.
|
|
|
|
## ترتیب ستونها در ایندکس مرکب
|
|
|
|
ایندکس چندستونی چند ایندکس جدا نیست، یک فهرست مرتب است و ترتیب ستونها تعیین میکند کدام کوئریها را سرو کند: اول شرطهای تساوی، بعد یک ستون بازه، بعد ستونهایی که فقط برای مرتبسازی یا پوششاند.
|
|
|
|
- فیلتر روی ستون tenant و بازه created_at از ایندکس روی هر دو استفاده میکند، چون بازه در اولین ستون بازهای متوقف میشود.
|
|
- فیلتر روی ستون کاربر و مرتبسازی بر اساس created_at نزولی هم کار میکند، چون موتور ایندکس را از عقب میخواند.
|
|
- اضافهکردن یک ستون تساوی در ابتدا معمولاً ایندکس تکستونی قبلی را بیفایده میکند.
|
|
- جهتی را تست کنید که واقعاً کوئری میزنید، چون ترکیب صعودی و نزولی کاری را که موتور میتواند انجام دهد تغییر میدهد.
|
|
|
|
## ایندکس پوششی
|
|
|
|
ایندکس پوششی هر ستونی را که کوئری لازم دارد نگه میدارد، پس دیتابیس از خود ایندکس پاسخ میدهد و اصلاً به جدول دست نمیزند. این ستونها را به ایندکس موجود اضافه کنید نه اینکه ایندکس تازه بسازید، و در ستون extra دنبال کلمه covering بگردید. نکته، هزینه نوشتن است، پس این روش برای چند کوئری داغ شماست.
|
|
|
|
## کلید خارجی و هزینه ایندکس زیاد
|
|
|
|
ستون کلید خارجی به دلیلی مستقل از راحتی کاربرد به ایندکس نیاز دارد: وقتی ردیفی حذف میشود، موتور باید ثابت کند هیچ ردیف فرزندی به آن اشاره نمیکند و بدون ایندکس این بررسی به اسکن کامل جدول تبدیل میشود در حالی که قفل نگه داشته شده است.
|
|
|
|
- روی هر ستون کلید خارجی و هر ستون join ایندکس بگذارید، ارزانترین برد کارایی در کل سیستم همین است.
|
|
- روی ستونهایی که فیلتر، مرتبسازی و join میشوند ایندکس بگذارید، اما ستونهای فقط select را نه.
|
|
- در لاراول ایندکسها را داخل مایگریشن بنویسید، نه در یک نشست کنسول دستی.
|
|
- در تست تمام کوئریها را لاگ بگیرید، این کار بازگشت الگوی N بهعلاوه یک را قبل از پروداکشن میگیرد.
|
|
|
|
## جمعبندی
|
|
|
|
- ایندکس یک درخت B است، پس مرتبسازی و اسکن بازهای ارزان میشود و هر نوشتن هزینه میدهد.
|
|
- قبل از دستزدن به کد، نوع دسترسی، تعداد ردیف تخمینی و extra را در EXPLAIN بخوانید.
|
|
- اول ستونهای تساوی، بعد یک ستون بازه، بعد ستونهای مرتبسازی.
|
|
- ایندکس پوششی بدون دستزدن به جدول پاسخ میدهد، پس روی مسیرهای داغ نگهش دارید.
|
|
- روی هر کلید خارجی ایندکس بگذارید و کل مجموعه را کوچک نگه دارید.
|
|
|
|
## FAQ
|
|
|
|
Q: چطور بفهمم کدام ایندکسها واقعاً در پروداکشن استفاده میشوند؟
|
|
|
|
A: performance schema یا لاگ کوئریهای کند ارائهدهنده را روشن کنید و کوئریهای مهم را با تعریف ایندکسها مقایسه کنید. در MySQL همین بخش شمارندهای بهازای هر جدول برای ایندکسهای استفادهنشده میدهد و حذف آنها بعد از یک بازه ترافیک نماینده، امنترین راه برداشتن ایندکسی است که فقط نوشتن را کند میکند.
|
|
|
|
Q: ایندکس گذاشتن روی هر ستونی که در WHERE میآید کار بدی است؟
|
|
|
|
A: بهمحض اینکه حجم نوشتن مهم شود بد میشود، چون هر ایندکس با هر insert و update بهروز میشود. بهجایش بپرسید کدام کوئریها پرتکرار یا کند هستند، چون یک ایندکس مرکب با ترتیب درست معمولاً چند شرط را با هم پوشش میدهد.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'تایپاسکریپت فراتر از مقدمات: ژنریکها، تایپهای کاربردی و حالت سختگیرانه در پروژههای واقعی',
|
|
'slug' => 'typescript-advanced-patterns-fa',
|
|
'excerpt' => 'بیشتر تیمها تایپاسکریپت را فقط بهعنوان یک لینتر به کار میبرند. ژنریکهایی که تایپ دامنه را حفظ میکنند، چند تایپ کاربردی مشخص و دو فلگ کامپایلر که از آنها میگذرند، کامپایلر را به ابزار بازآرایی کد تبدیل میکنند.',
|
|
'category' => 'frontend-fa',
|
|
'tags' => ['typescript-fa', 'clean-code-fa'],
|
|
'cover' => 'الگوهای تایپاسکریپت در پروژه واقعی',
|
|
'views' => 2180,
|
|
'likes' => 142,
|
|
'days_ago' => 4,
|
|
'body' => <<<'TEXT'
|
|
# تایپاسکریپت فراتر از مقدمات: ژنریکها، تایپهای کاربردی و حالت سختگیرانه در پروژههای واقعی
|
|
|
|
بیشتر تیمها تایپاسکریپت را برای تکمیل خودکار و برای اینکه دیگر اشتباه کلاسیک رشته در برابر عدد را تحویل ندهند اضافه میکنند. شش ماه بعد کد پر است از cast به any و از تنظیمات کامپایلری که هیچکس جرئت دستزدن به آن را ندارد. این فاصله، مسأله واژگان است نه تلاش.
|
|
|
|
## ژنریکهایی که واقعاً ارزش دارند
|
|
|
|
یک ژنریک وقتی جای خود را توجیه میکند که یک منطق واحد باید چند شکل مختلف را بدون از دست رفتن اطلاعات تایپی هر کدام ادامه دهد. اگر انتهای پیادهسازی با یک cast بسته شود، یک تابع ساده میخواستید.
|
|
|
|
- یک ریپازیتوری که تایپ موجودیت را یک بار میگیرد و همان را از همه متدها برمیگرداند.
|
|
- یک فرمساز که هر فیلد تایپ مقدار خودش را اعلام میکند و نتیجه از روی همان فیلدها استنتاج میشود.
|
|
- یک کامپوننت جدول که تایپ سطر بههمراه توابع دسترسی را میگیرد تا مرتبسازی در هر ستون درست بماند.
|
|
- یک ایونتامیتر تایپشده که نگاشت آن هم محموله رویداد و هم نامهای مجاز را تعریف میکند.
|
|
|
|
دو قید بار اصلی را به دوش میکشند، چون کیدوف T فقط کلیدهایی را میپذیرد که تایپ واقعاً دارد و extends string ورودی را داخل یک خانواده شناختهشده نگه میدارد.
|
|
|
|
## تایپهای کاربردیای که واقعاً به آنها نیاز دارید
|
|
|
|
هیچکس صد تایپ کاربردی را حفظ نمیکند. یک مجموعه کوتاه تقریباً همه نیاز را پوشش میدهد و ترکیب آنها در یک别名 نامدار، بهتر از اختراع تایپ تازه برای هر مدل است.
|
|
|
|
- Partial برای داده ارسالی ویرایش و مدل فرم.
|
|
- Pick و Omit برای ساخت DTO درخواست بدون تکرار نام فیلدها.
|
|
- ReturnType و Parameters تا یک هوک یک بار شکل خودش را تعریف کند.
|
|
- NonNullable برای مقدارهایی که از ستون nullable برمیگردند.
|
|
- Record برای دیکشنری تایپشده بهجای ایندکسسیگنچر باز.
|
|
- Awaited برای باز کردن پرامیسهایی که کلاینتها برمیگردانند.
|
|
|
|
## دو فلگ کامپایلر که همه از آنها میگذرند
|
|
|
|
حالت سختگیرانه خط پایه است. ارتقایی که تقریباً هیچکس روشن نمیکند noUncheckedIndexedAccess است و بیشترین باگهای واقعی را میگیرد، چون خواندن بیرون از محدوده رایجترین منبع undefined در زمان اجراست.
|
|
|
|
- دسترسی به آرایه و رکورد به مقدار یا undefined تبدیل میشود و خواندن خارج از محدوده دیگر کامپایل نمیشود.
|
|
- بررسی null در حالت سختگیرانه مجبورتان میکند نبودن مقدار را مدیریت کنید، نه اینکه آن را با ادعای not-null سرپوش بگذارید.
|
|
- exactOptionalPropertyTypes جلوی دادن undefined به فیلد اختیاری را میگیرد.
|
|
- noImplicitOverride و فلگ خطای switch در ارثبری، اشتباهها را جمع میکنند.
|
|
|
|
روشنکردن اینها روی کدبیس قدیمی موج خطا میسازد، پس آنها را برای ماژولهای جدید فعال کنید و فایلها را همانوقت که رویشان کار میکنید درست کنید.
|
|
|
|
## یونیونهای تفکیکشده بهتر از فیلدهای اختیاریاند
|
|
|
|
آبجکتی با سه مقدار بولی و چهار فیلد nullable، هشت حالت معنادار دارد و کامپایلر هیچکدام را بررسی نمیکند. یونیونی با یک فیلد وضعیت literal، ترکیبهای نامعتبر را به خطای تایپی تبدیل میکند.
|
|
|
|
- یک پرداخت را بهصورت created، captured یا refunded مدل کنید، نه یک رشته وضعیت با فیلدهای nullable.
|
|
- جریان فرم را یونیونی از آبجکتهای مرحلهای مدل کنید که هر مرحله فقط داده خودش را حمل میکند.
|
|
- با switch روی فیلد تفکیککننده ناریکی ایجاد کنید تا یونیون داخل هر شاخه باریک شود.
|
|
|
|
## کجا باید متوقف شویم
|
|
|
|
برنامهنویسی در سطح تایپ سقفی دارد و عبور از آن، سریعترین راهی است که یک تیم اعتمادش را به تایپهای خودش از دست میدهد.
|
|
|
|
- تایپی نسازید که برایش توضیحی بلندتر از کدی که جایگزینش میشود لازم باشد.
|
|
- یک پیادهسازی را پشت پارامتر ژنریک پنهان نکنید تا پیادهسازی دومی واقعاً وجود داشته باشد.
|
|
- قواعد کسبوکار را در تایپها کدنویسی نکنید، حالتها و روابط را کدنویسی کنید.
|
|
- داده بیرونی را یک بار در مرز ورودی پارس کنید و بعد همان تایپ را همه جا استفاده کنید.
|
|
|
|
## جمعبندی
|
|
|
|
- ژنریک را فقط وقتی اضافه کنید که شکلها رفتار مشترک داشته باشند و قابل تشخیص بمانند.
|
|
- یک مجموعه کوتاه از تایپهای کاربردی را نگه دارید و آنها را ترکیب کنید.
|
|
- اول noUncheckedIndexedAccess را روشن کنید و بعد بقیه فلگهای سختگیرانه را فایل به فایل.
|
|
- خوشههای فیلد nullable را با یونیونهای تفکیکشده جایگزین کنید.
|
|
- قبل از اینکه تایپها از منطق سختتر خوانده شوند، متوقف شوید.
|
|
|
|
## FAQ
|
|
|
|
Q: کد سنگین در سطح تایپ کامپایلر را در کدبیس بزرگ کند میکند؟
|
|
|
|
A: گاهی بله، و این هزینه روی بزرگترین فایلها مینشیند نه روی کل پروژه. تایپهای نگاشتی عمیق و کد ژنریکی که با یونیونهای بزرگ نمونهسازی میشود، مقصر رایجاند. پس بهجای حذف فلگها، چند تایپ پیچیده را ساده کنید.
|
|
|
|
Q: حالت سختگیرانه را یکجا روی کدبیس موجود فعال کنم؟
|
|
|
|
A: نه، یکجا نه. فلگها را برای پوشههای قدیمی از بیلد سراسری بیرون نگه دارید، برای ماژولهای جدید بلافاصله اعمال کنید و خطاها را در دستههای کوچک و هر بار روی یک فایل رفع کنید.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'وقتی مرورگر یک صفحه را باز میکند',
|
|
'slug' => 'how-the-browser-loads-a-page-fa',
|
|
'excerpt' => 'از DNS تا امتیاز ۹۰ Lighthouse، گامبهگام بررسی میکنیم که مرورگر چطور صفحه را بارگذاری میکند و چه کارهایی باعث بهبود سرعت و تجربه کاربری میشود.',
|
|
'category' => 'web-performance-seo-fa',
|
|
'tags' => ['performance-fa', 'seo-fa'],
|
|
'cover' => 'وقتی مرورگر یک صفحه را باز میکند',
|
|
'views' => 2150,
|
|
'likes' => 138,
|
|
'days_ago' => 15,
|
|
'body' => <<<'TEXT'
|
|
# وقتی مرورگر یک صفحه را باز میکند
|
|
|
|
وقتی کاربر یک آدرس را در مرورگر تایپ میکند و Enter میزند، در کسری از ثانیه اتفاقهای زیادی میافتد. فهمیدن این روند فقط تئوری نیست؛ به شما کمک میکند سایتهای کند را دیباگ کنید، اولویت درست بدهید و هم تجربه کاربری و هم سئو را بهتر کنید. در ادامه قدمبهقدم توضیح میدهیم چه میشود و هر مرحله چطور روی عملکرد اثر میگذارد.
|
|
|
|
## DNS و برقراری اتصال اولیه
|
|
|
|
اولین قدم، تبدیل نام دامنه به آدرس IP است. مرورگر اول کش خودش را چک میکند، بعد کش سیستمعامل، روتر و در نهایت سرورهای DNS. DNS کند باعث افزایش تأخیر میشود، مخصوصاً در شبکههای موبایل.
|
|
|
|
بعد از پیدا شدن IP، مرورگر اتصال TCP برقرار میکند. برای سایتهای HTTPS، این شامل دستداد TLS برای رمزنگاری هم میشود. TLS ۱٫۳ نسبت به نسخههای قدیمی تعداد دورهای لازم برای handshake را کاهش داده است. استفاده مجدد از اتصال (Connection Reuse) با keep-alive یا Multiplexing در HTTP/2 از تکرار این هزینه برای هر منبع جلوگیری میکند.
|
|
|
|
## درخواستهای HTTP و پروتکلهای اتصال
|
|
|
|
سایتهای مدرن از HTTP/2 یا HTTP/3 استفاده میکنند. در HTTP/1.1 مرورگر محدودیت تعداد درخواست همزمان در هر دامنه داشت که باعث آبشاری شدن درخواستها میشد. HTTP/2 اجازه میدهد چندین درخواست بهصورت همزمان روی یک اتصال ردوبدل شوند. HTTP/3 از QUIC روی UDP استفاده میکند و Head-of-Line Blocking را کاهش میدهد و روی شبکههای ناپایدار عملکرد بهتری دارد.
|
|
|
|
مرورگر ابتدا سند HTML را درخواست میکند. معمولاً فایل کوچکی است ولی کلید بارگذاری بقیه منابع است. نحوه تحویل آن توسط سرور، فشردهسازی (gzip یا Brotli) و هدرهای کش همگی روی زمان بارگذاری اولیه اثر میگذارند.
|
|
|
|
## پارس HTML و ساخت DOM
|
|
|
|
مرورگر همزمان با دریافت بایتهای HTML، آن را به Token تبدیل میکند و سپس درخت DOM را میسازد. این فرایند جریانی است؛ یعنی مرورگر میتواند قبل از دریافت کامل فایل، پارس را شروع کند. اما اگر به اسکریپت همگام (Synchronous) بدون defer یا async برسد، پارس HTML متوقف میشود.
|
|
|
|
در حین پارس HTML، مرورگر به منابع خارجی مثل CSS، اسکریپت، تصویر، فونت و غیره اشارههایی پیدا میکند. هرکدام باعث ارسال درخواست جدیدی میشود که بسته به پروتکل و اولویت، یا در صف میماند یا بلافاصله ارسال میشود.
|
|
|
|
## CSS حیاتی و منابع مسدودکننده رندر
|
|
|
|
CSS بهصورت پیشفرض رندر را مسدود میکند. مرورگر تا زمانی که CSSOM (مدل شیء CSS) کامل نشود، نمیتواند محتوا را نمایش دهد. فایلهای CSS بزرگ و بهینهنشده، زمان اولین نمایش (First Paint) را به تأخیر میاندازند. یک بهینهسازی رایج، استخراج و Inline کردن CSS حیاتی برای بخش بالای صفحه (Above-the-fold) و بارگذاری بقیه بهصورت غیرهمگام است.
|
|
|
|
جاوااسکریپت اثر بیشتری دارد. اسکریپتهای همگام پارس HTML را مسدود میکنند و رندر را به تأخیر میاندازند. استفاده از script با type=module، defer یا async زمان اجرا را تغییر میدهد. defer ترتیب اجرا را حفظ میکند و بعد از تکمیل DOM اجرا میشود. async بلافاصله بعد از دانلود اجرا میشود و ترتیب را رعایت نمیکند. انتقال اسکریپتهای غیرحیاتی به انتهای صفحه یا استفاده از defer، کلید بهبود عملکرد محسوس است.
|
|
|
|
## Preload، Prefetch و Resource Hintها
|
|
|
|
همه منابع همزمان کشف نمیشوند. مرورگر از یک Preload Scanner استفاده میکند تا منابعی را که در ادامه HTML آمدهاند زودتر پیدا کند. همچنین میتوانید Hintهای صریح بدهید: link rel=preload برای منابع حیاتی مثل فونت یا تصویر اصلی، preconnect برای برقراری زودتر اتصال به دامنههای مهم و prefetch برای منابعی که احتمالاً در صفحه بعد نیاز دارند.
|
|
|
|
این Hintها به مرورگر کمک میکنند اولویتها را درست تنظیم کند و بدون بار اضافی روی شبکه، تأخیرها را کاهش دهند.
|
|
|
|
## تصاویر، فونتها و پایداری چیدمان
|
|
|
|
تصاویر معمولاً بزرگترین حجم بایت را دارند. بهینهسازیهایی مثل فرمتهای مدرن (WebP، AVIF)، استفاده از srcset پاسخگو، Lazy Loading برای تصاویر خارج از دید و تعیین سایز مناسب، هم حجم را کاهش میدهند و هم از جابجایی چیدمان جلوگیری میکنند. رمزگشایی تصاویر بزرگ هم میتواند Main Thread را مسدود کند؛ استفاده از decoding=async و سایز مناسب کمک میکند.
|
|
|
|
فونتها هم اگر درست مدیریت نشوند باعث متن نامرئی یا جابجایی چیدمان میشوند. font-display: swap بلافاصله متن جایگزین را نمایش میدهد تا فونت وب بارگذاری شود و تجربه کاربری بهتری دارد. Preload کردن فونتهای حیاتی احتمال FOIT (Flash of Invisible Text) را کاهش میدهد.
|
|
|
|
Cumulative Layout Shift (CLS) زمانی رخ میدهد که محتوا بعد از رندر اولیه جابهجا میشود. رزرو کردن فضای لازم برای تصاویر، تبلیغات یا محتواهای داینامیک، مؤثرترین راه کاهش CLS است.
|
|
|
|
## Pipeline رندر و Core Web Vitals
|
|
|
|
وقتی CSSOM و DOM آماده شدند، مرورگر Render Tree میسازد، Layout محاسبه میکند، پیکسلها Paint میشوند و لایهها Composite میگردند. این فرایند فریمبهفریم انجام میشود. Taskهای طولانی روی Main Thread باعث کند شدن تعامل کاربر میشوند.
|
|
|
|
Core Web Vitals مستقیماً به همین Pipeline مربوطاند. Largest Contentful Paint (LCP) زمان بارگذاری بزرگترین عنصر قابلمشاهده مثل تصویر اصلی یا تیتر را اندازه میگیرد. Interaction to Next Paint (INP) پاسخگویی به ورودی کاربر را میسنجد. Cumulative Layout Shift (CLS) پایداری بصری را اندازه میگیرد. این معیارها تأثیر زیادی روی امتیاز Lighthouse و رتبه سئو دارند.
|
|
|
|
## رسیدن به امتیاز ۹۰ Lighthouse
|
|
|
|
رسیدن به ۹۰+ با تمرکز روی اصلاحات پراثر قابلدسترس است. تصاویر را بهینه کنید و با فرمتهای مدرن سرو کنید. اسکریپتهای غیرحیاتی را Defer یا Lazy Load کنید. CSS حیاتی را Inline کنید و منابع مسدودکننده رندر را کاهش دهید. از هدرهای کش و CDN برای کاهش Time to First Byte (TTFB) استفاده کنید. به دامنههای ثالث preconnect کنید و منابع حیاتی را preload کنید. در نهایت با رزرو فضای مناسب برای عناصر داینامیک، جابجایی چیدمان را به حداقل برسانید.
|
|
|
|
کلید این نیست که همهچیز را انجام دهید، بلکه این است که آنچه مسیر حیاتی صفحه شما را مسدود میکند اصلاح کنید. با Chrome DevTools و Lighthouse پروفایل بگیرید، اندازهگیری کنید و مرحلهبهمرحله پیش بروید.
|
|
|
|
## نکات کلیدی
|
|
|
|
- DNS، TCP و TLS تأخیر اتصال ایجاد میکنند؛ از اتصال مجدد استفاده کنید و HTTP/2 یا HTTP/3 را بهکار ببرید.
|
|
- پارس HTML جریانی است ولی با اسکریپت همگام متوقف میشود؛ برای JS غیرحیاتی از defer یا async استفاده کنید.
|
|
- CSS رندر را مسدود میکند؛ CSS حیاتی را Inline کنید و بقیه را بهینه بارگذاری کنید.
|
|
- منابع حیاتی را preload کنید و به دامنههای مهم preconnect کنید تا تأخیر کاهش یابد.
|
|
- تصاویر، فونتها و چیدمان را بهینه کنید تا LCP، INP و CLS بهتر شوند و امتیاز Lighthouse افزایش یابد.
|
|
|
|
## FAQ
|
|
|
|
Q: بزرگترین عامل مؤثر روی LCP چیست؟
|
|
A: معمولاً تصویر اصلی یا بزرگترین عنصر قابلمشاهده است. بهینهسازی سایز، فرمت و اولویت بارگذاری آن بیشترین تأثیر را دارد.
|
|
|
|
Q: برای اسکریپتها از async یا defer استفاده کنم؟
|
|
A: برای اسکریپتهایی که به ترتیب DOM وابستهاند از defer استفاده کنید. برای اسکریپتهای مستقل مثل آنالیتیکس که بلافاصله نیاز نیست از async استفاده کنید.
|
|
|
|
Q: HTTP/3 چطور عملکرد را بهتر میکند؟
|
|
A: HTTP/3 از QUIC روی UDP استفاده میکند، Head-of-Line Blocking را کاهش میدهد و در مواجهه با از دست رفتن بستهها، مخصوصاً در شبکههای موبایل یا ناپایدار، سریعتر بازیابی میشود.
|
|
TEXT,
|
|
],
|
|
|
|
[
|
|
'title' => 'توسعه آزمونمحور و کد آزمونپذیر',
|
|
'slug' => 'tdd-writing-testable-code-fa',
|
|
'excerpt' => 'توسعه آزمونمحور را فقط در جاهایی بهکار بگیرید که سرعت توسعه را افزایش میدهد و با سه لایهسازی مناسب، تستها را سریع و کاربردی نگه دارید.',
|
|
'category' => 'engineering-practices-fa',
|
|
'tags' => ['testing-fa', 'clean-code-fa'],
|
|
'cover' => 'توسعه آزمونمحور و کد آزمونپذیر',
|
|
'views' => 1480,
|
|
'likes' => 112,
|
|
'days_ago' => 12,
|
|
'body' => <<<'TEXT'
|
|
# توسعه آزمونمحور و کد آزمونپذیر
|
|
|
|
بحثهای زیادی درباره توسعه آزمونمحور وجود دارد. بعضیها آن را یک قانون مطلق میدانند و بعضیها آن را کاملاً بیفایده. واقعیت این است که توسعه آزمونمحور در برخی حوزهها ارزش زیادی دارد و در برخی دیگر فقط اضافهکاری میشود. مهمترین نکته این نیست که حتماً تست را اول بنویسید، بلکه هدف این است که کد آزمونپذیر بنویسید.
|
|
|
|
## کجا توسعه آزمونمحور واقعاً مفید است
|
|
|
|
بیشترین سود زمانی است که کد احتمال تغییر یا شکست زیادی دارد. قوانین کسبوکار بهترین مثال هستند. محاسبات قیمت، مالیات، تخفیف یا اعتبارسنجیها معمولاً حالات زیادی دارند. اگر اول یک تست شکستخورده بنویسید، این قوانین صراحتاً مشخص میشوند و از بروز خطاهای رجگریشن جلوگیری میکنید.
|
|
|
|
کارهای پارس کردن و تبدیل دادهها هم خیلی مفیدند. وقتی فرمتها را تبدیل میکنید، داده استخراج میکنید یا ورودیها را نرمالسازی میکنید، میتوانید با توسعه آزمونمحور مرحلهبهمرحله پیش بروید و هر تست، رفتار را ثابت نگه میدارد تا با خیال راحت ریفکتور کنید.
|
|
|
|
همچنین برای ریفکتور کردن کدهای قدیمی بسیار کمک میکند. اگر بتوانید قبل از تغییر، یک شبکه کوچک از تستهای سریع دور یک ماژول بسازید، میتوانید با اطمینان بیشتری آن را بازنویسی کنید. در نهایت هر جایی که ریسک رجگریشن بالاست، مثل احراز هویت، سطح دسترسی یا محاسبات مالی، ارزش سرمایهگذاری اولیه را دارد.
|
|
|
|
## کجا فقط اضافهکاری میشود
|
|
|
|
همه کدها نیاز به چرخه قرمزـسبز ندارند. نمونههای سریع رابط کاربری، اسکریپتهای یکبارمصرف انتقال داده یا پروتوتایپهایی که احتمالاً همان روز کنار گذاشته میشوند، معمولاً ارزش این کار را ندارند. همینطور کامپوننتهای کاملاً نمایشی که رفتارشان ساده است و مدام تغییر میکند.
|
|
|
|
هزینه فقط نوشتن تست نیست. هزینه نگهداری تستهایی است که دیگر رفتار مفیدی را پوشش نمیدهند و زمان زیادی میبرد تا با تغییرات هماهنگ شوند. در این موارد بهتر است بعد از تثبیت رفتار، تست بنویسید یا تا زمان مشخص شدن طراحی، از نوشتن تست صرفنظر کنید.
|
|
|
|
## قانون سه لایه برای آزمونپذیری
|
|
|
|
سادهترین راه برای نوشتن کد آزمونپذیر، تقسیم آن به سه لایه است. لایه منطق، شامل قوانین خالص کسبوکار بدون اثر جانبی است. این لایه بهترین مکان برای توسعه آزمونمحور است چون تستها بلافاصله اجرا میشوند و هیچ وابستگی ندارند.
|
|
|
|
لایه اثرات، مسئول ارتباط با بیرون است: دسترسی به دیتابیس، فراخوانی API، فایلسیستم، صفها و سرویسهای خارجی. این تستها کندترند و معمولاً نیاز به Mock یا جایگزین دارند. این لایه باید نازک نگه داشته شود و پیچیدگی را به لایه منطق منتقل کنید.
|
|
|
|
لایه رابط، با دنیای بیرون صحبت میکند؛ مثل کنترلرها، دستورات CLI یا هندلرهای رابط کاربری. این لایه فقط باید هماهنگکننده باشد و دادهها را تبدیل کند. اگر بیشتر پیچیدگی در لایه منطق باشد، تستهای لایه رابط کوچک میمانند و تستهای یکپارچگی هدفمندتر خواهند بود.
|
|
|
|
## نامگذاری و کیفیت آرگومانهای آزمون
|
|
|
|
تستها مستنداتی برای توسعهدهندگان آینده هستند. نام خوب تست باید رفتار را توضیح دهد، نه پیادهسازی را. بهجای testingFunctionReturnsTrue بهتر بگویید shouldApplyDiscountWhenSubtotalExceedsThreshold. این کار باعث میشود خطاها خواناتر باشند و هدف تست واضحتر باشد.
|
|
|
|
Assertions هم به همان اندازه مهماند. از Assertions دقیق و شفاف استفاده کنید و از بررسی جزئیات پیادهسازی مثل متدهای خصوصی یا ساختار داخلی اشیاء پرهیز کنید. روی رفتار قابلمشاهده تست کنید: ورودی، خروجی، اثرات جانبی مهم یا تغییراتی که از API عمومی قابلمشاهدهاند. این کار تستها را در برابر ریفکتور مقاومتر میکند.
|
|
|
|
## تستها را سریع نگه دارید تا همیشه اجرا شوند
|
|
|
|
سرعت مهمترین ویژگی یک مجموعه تست کاربردی است. اگر اجرای تستها چند دقیقه طول بکشد، فقط در CI اجرا میشوند. اگر چند ثانیه باشد، قبل از هر کامیت اجرا میشوند. همین تفاوت است بین پیدا کردن باگ زودهنگام و کشف آن چند ساعت بعد.
|
|
|
|
برای سرعت بالا، در تستهای واحد از دیتابیس واقعی، شبکه یا فایلسیستم استفاده نکنید. از Fake، Stub یا پیادهسازی در حافظه استفاده کنید. تستهای کند را فقط برای مسیرهای حیاتی یکپارچگی نگه دارید و آنها را جدا کنید. حلقه بازخورد سریع باعث میشود توسعه آزمونمحور سرعت توسعه را افزایش دهد نه کاهش.
|
|
|
|
## نکات کلیدی
|
|
|
|
- توسعه آزمونمحور را در جاهایی بهکار بگیرید که رفتار بهاندازه کافی پایدار است: قوانین کسبوکار، پارس کردن، ریفکتور و نواحی با ریسک رجگریشن بالا.
|
|
- در نمونههای سریع رابط کاربری، پروتوتایپ یا آزمایشهای پر تغییر، آن را کنار بگذارید یا به بعد موکول کنید.
|
|
- از قانون سه لایه استفاده کنید: منطق، اثرات و رابط تا پیچیدگی جدا شود.
|
|
- تستها را بر اساس رفتار نامگذاری کنید و روی نتایج قابلمشاهده Assert کنید، نه جزئیات داخلی.
|
|
- سرعت را اولویت دهید تا تستها قبل از هر کامیت اجرا شوند و بازخورد سریع بماند.
|
|
|
|
## FAQ
|
|
|
|
Q: آیا همیشه باید اول تست بنویسم؟
|
|
A: نه. وقتی نیازمندیها آنقدر شفافاند که میتوان رفتار مورد انتظار را مشخص کرد، اول تست بنویسید. اگر طراحی هنوز در حال تغییر است، بهتر است اول پیادهسازی کنید و بعد از تثبیت شکل، تست اضافه کنید.
|
|
|
|
Q: چه میزان پوشش تست کافی است؟
|
|
A: روی مسیرهای حیاتی و حالات خاص تمرکز کنید، نه دنبال پوشش ۱۰۰٪. پوشش بالا روی کد پیشپاافتاده ارزش کمی دارد. پوشش خوب روی منطق حیاتی کسبوکار، از رجگریشنهای واقعی جلوگیری میکند.
|
|
|
|
Q: برای نوشتن کد آزمونپذیر حتماً باید از توسعه آزمونمحور استفاده کنم؟
|
|
A: نه. توسعه آزمونمحور روشی است که معمولاً کد آزمونپذیر تولید میکند، اما میتوانید بهتدریج کد را به سمت آزمونپذیری ریفکتور کنید. هدف، کد آزمونپذیر با تستهای سریع و معنادار است، نه رعایت دقیق همه قواعد.
|
|
TEXT,
|
|
],
|
|
];
|
|
|
|
$now = now();
|
|
$frontUrl = env('FRONT_URL', 'https://parsaaghayi.ir');
|
|
$postIds = [];
|
|
|
|
foreach ($posts as $index => $post) {
|
|
$created = Post::create([
|
|
'title' => $post['title'],
|
|
'slug' => $post['slug'],
|
|
'body' => $post['body'],
|
|
'excerpt' => $post['excerpt'],
|
|
'author_id' => $author->id,
|
|
'category_id' => $categoryIds[$post['category']],
|
|
'featured_image' => $frontUrl.'/og-image?text='.rawurlencode($post['cover']),
|
|
'views' => $post['views'],
|
|
'likes' => $post['likes'],
|
|
'published_at' => $now->copy()->subDays($post['days_ago']),
|
|
]);
|
|
|
|
$postIds[$index] = $created->id;
|
|
|
|
$created->tags()->attach(
|
|
array_map(fn ($tag) => $tagIds[$tag], $post['tags'])
|
|
);
|
|
}
|
|
|
|
// Related posts: keep every "you might like" list inside the reader's
|
|
// language. The blog is a strict English/Persian mirror, so a reader on
|
|
// the Persian version must never see English cards and vice versa.
|
|
$byLanguage = ['en' => [], 'fa' => []];
|
|
|
|
foreach ($posts as $index => $post) {
|
|
$lang = str_ends_with($post['slug'], '-fa') ? 'fa' : 'en';
|
|
$byLanguage[$lang][] = $postIds[$index];
|
|
}
|
|
|
|
foreach ($byLanguage as $ids) {
|
|
foreach ($ids as $ownerId) {
|
|
$owner = Post::find($ownerId);
|
|
$owner->relatedPosts()->attach(
|
|
collect($ids)->reject(fn ($id) => $id === $ownerId)->values()->all()
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->command->info('Real blog content seeded: '
|
|
.count($categories).' categories, '
|
|
.count($tags).' tags, '
|
|
.count($posts).' posts.');
|
|
}
|
|
} |